Changeset 11814
- Timestamp:
- 09/27/08 12:42:29 (5 years ago)
- Files:
-
- branches/1.2/UPGRADE_TO_1_2 (modified) (1 diff)
- branches/1.2/lib/form/sfForm.class.php (modified) (1 diff)
- branches/1.2/test/unit/form/sfFormTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/UPGRADE_TO_1_2
r11805 r11814 336 336 <?php endif; ?> 337 337 338 A new `renderUsing` method has been added to the `sfForm` class, allowing to 339 render the form using a particular widget schema formatter. This allows to 340 use a formatter directly within a template: 341 342 [php] 343 // in a template, the form will be rendered using the "list" form formatter 344 echo $form->renderUsing('list'); 345 338 346 Validators 339 347 ---------- branches/1.2/lib/form/sfForm.class.php
r11708 r11814 120 120 121 121 /** 122 * Renders the widget schema using a specific form formatter 123 * 124 * @param string $formatterName The form formatter name 125 * @param array $attributes An array of HTML attributes 126 * 127 * @return string The rendered widget schema 128 */ 129 public function renderUsing($formatterName, $attributes = array()) 130 { 131 $currentFormatterName = $this->widgetSchema->getFormFormatterName(); 132 133 $formatterClass = sprintf('sfWidgetFormSchemaFormatter%s', ucfirst($formatterName)); 134 135 if (!class_exists($formatterClass)) 136 { 137 throw new InvalidArgumentException(sprintf('Formatter "%s" (class "%s") does not exist', $formatterName, $formatterClass)); 138 } 139 140 $this->widgetSchema->setFormFormatterName($formatterName); 141 142 $output = $this->render($attributes); 143 144 $this->widgetSchema->setFormFormatterName($currentFormatterName); 145 146 return $output; 147 } 148 149 /** 122 150 * Renders global errors associated with this form. 123 151 * branches/1.2/test/unit/form/sfFormTest.php
r11701 r11814 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(10 6, new lime_output_color());13 $t = new lime_test(108, new lime_output_color()); 14 14 15 15 class FormTest extends sfForm … … 321 321 $t->is($f->render(array('first_name' => array('class' => 'foo'))), $output, '->render() renders the form as HTML'); 322 322 323 // renderUsing() 324 $t->diag('->renderUsing()'); 325 $f = new sfForm(); 326 $f->setWidgets(array('name' => new sfWidgetFormInput())); 327 $output = <<<EOF 328 <li> 329 <label for="name">Name</label> 330 <input type="text" name="name" id="name" /> 331 </li> 332 333 EOF; 334 $t->is($f->renderUsing('list'), $output, 'renderUsing() renders the widget schema using the given form formatter'); 335 $t->is($f->getWidgetSchema()->getFormFormatterName(), 'table', 'renderUsing() does not persist form formatter name for the current form instance'); 336 323 337 // ->embedForm() 324 338 $t->diag('->embedForm()');