Changeset 11185 for plugins/sfFormtasticPlugin
- Timestamp:
- 08/27/08 01:42:03 (5 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfFormtasticPlugin/trunk/lib/form/sfFormtasticBase.class.php
r10453 r11185 107 107 { 108 108 $this->checkCSRFField(); 109 $this->applyIdFormat();110 109 111 110 return parent::render($attributes); … … 119 118 public function renderHiddenFields() 120 119 { 121 $ this->checkCSRFField();122 $this->applyIdFormat();123 124 $rendered = array();125 foreach ($this->getFormFieldSchema()->getHiddenFields() as $field)126 {127 $rendered[] = $field->render();128 } 129 130 return join("\n", $rendered);120 $clone = clone $this; 121 foreach ($clone->getFormFieldSchema() as $name => $field) 122 { 123 if (!$field->isHidden()) 124 { 125 unset($clone[$name]); 126 } 127 } 128 129 return $clone->render(); 131 130 } 132 131 … … 143 142 } 144 143 145 $this-> setOption('id_format', $format);144 $this->widgetSchema->setOption('id_format', $format); 146 145 } 147 146 … … 153 152 public function getIdFormat() 154 153 { 155 return $this->getOption('id_format'); 156 } 157 158 /** 159 * Apply id format to the widgets, if configured. 160 */ 161 protected function applyIdFormat() 162 { 163 if (!is_null($format = $this->getIdFormat())) 164 { 165 foreach ($this->widgetSchema->getFields() as $widget) 166 { 167 if ($widget instanceof sfWidgetForm) 168 { 169 $widget->setIdFormat($format); 170 } 171 } 172 } 154 return $this->widgetSchema->getOption('id_format'); 173 155 } 174 156 … … 214 196 public function removeField($name) 215 197 { 216 unset($ name);198 unset($this[$name]); 217 199 } 218 200 plugins/sfFormtasticPlugin/trunk/lib/form/sfFormtasticFieldSchemaBase.class.php
r10209 r11185 14 14 class sfFormtasticFieldSchemaBase extends sfFormFieldSchema 15 15 { 16 /**17 * @return array All hidden form fields18 */19 public function getHiddenFields()20 {21 $hiddenFields = array();22 foreach ($this as $field)23 {24 if ($field->isHidden())25 {26 $hiddenFields[] = $field;27 }28 }29 30 return $hiddenFields;31 }32 16 } plugins/sfFormtasticPlugin/trunk/test/unit/sfFormtasticBaseTest.php
r10535 r11185 35 35 $t->diag('->setIdFormat()'); 36 36 37 try 38 { 39 $form->setIdFormat('foo'); 40 $t->fail('->setIdFormat() throws an exception when parameter does not include "%s"'); 41 } 42 catch (InvalidArgumentException $e) 43 { 44 $t->pass('->setIdFormat() throws an exception when parameter does not include "%s"'); 45 } 46 37 47 $form->setIdFormat('my_id_format_%s'); 38 $t->is($form->get Option('id_format'), 'my_id_format_%s', '->setIdFormat() sets the"id_format" option');48 $t->is($form->getWidgetSchema()->getOption('id_format'), 'my_id_format_%s', '->setIdFormat() sets the widgetSchema "id_format" option'); 39 49 $t->is($form->getIdFormat(), 'my_id_format_%s', '->getIdFormat() returns the "id_format" option'); 40 50 $t->like($form->render(), '/id="my_id_format_/', '->render() respects global id format'); … … 42 52 43 53 $form->setIdFormat(false); 44 $t->like($form->render(), '/id="email"/', '"->setIdFormat(false)" resets id attribute on labeled fields'); 45 $t->unlike($form->render(), '/id="\w*_csrf_token/', '"->setIdFormat(false)" removes id attribute on non-labeled fields'); 54 $t->unlike($form->render(), '/id="/', '"->setIdFormat(false)" removes id attribute');