Changeset 8485
- Timestamp:
- 04/16/08 19:41:41 (6 months ago)
- Files:
-
- branches/1.1/lib/form/sfFormField.class.php (modified) (4 diffs)
- branches/1.1/lib/widget/sfWidgetFormSchema.class.php (modified) (3 diffs)
- branches/1.1/lib/widget/sfWidgetFormSchemaDecorator.class.php (modified) (1 diff)
- branches/1.1/test/unit/form/sfFormFieldTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/form/sfFormField.class.php
r8408 r8485 71 71 * The formatted row will use the parent widget schema formatter. 72 72 * The formatted row contains the label, the field, the error and 73 * the help message if given. 74 * 75 * @param string The help text 73 * the help message. 74 * 75 * @param array An array of HTML attributes to merge with the current attributes 76 * @param string The label name (not null to override the current value) 77 * @param string The help text (not null to override the current value) 76 78 * 77 79 * @return string The formatted row 78 80 */ 79 public function renderRow($ help = '')81 public function renderRow($attributes = array(), $label = null, $help = null) 80 82 { 81 83 if (is_null($this->parent)) … … 84 86 } 85 87 86 $field = $this->parent->getWidget()->renderField($this->name, $this->value, $this->error);88 $field = $this->parent->getWidget()->renderField($this->name, $this->value, !is_array($attributes) ? array() : $attributes, $this->error); 87 89 88 90 $error = $this->error instanceof sfValidatorErrorSchema ? $this->error->getGlobalErrors() : $this->error; 89 91 90 return strtr($this->parent->getWidget()->getFormFormatter()->formatRow($this->renderLabel(), $field, $error, $help), array('%hidden_fields%' => '')); 92 $help = is_null($help) ? $this->parent->getWidget()->getHelp($this->name) : $help; 93 94 return strtr($this->parent->getWidget()->getFormFormatter()->formatRow($this->renderLabel($label), $field, $error, $help), array('%hidden_fields%' => '')); 91 95 } 92 96 … … 113 117 * Returns the label tag. 114 118 * 119 * @param string The label name (not null to override the current value) 120 * 115 121 * @return string The label tag 116 122 */ 117 public function renderLabel( )123 public function renderLabel($label = null) 118 124 { 119 125 if (is_null($this->parent)) … … 122 128 } 123 129 124 return $this->parent->getWidget()->getFormFormatter()->generateLabel($this->name); 130 if (!is_null($label)) 131 { 132 $currentLabel = $this->parent->getWidget()->getLabel($this->name); 133 $this->parent->getWidget()->setLabel($this->name, $label); 134 } 135 136 $html = $this->parent->getWidget()->getFormFormatter()->generateLabel($this->name); 137 138 if (!is_null($label)) 139 { 140 $this->parent->getWidget()->setLabel($this->name, $currentLabel); 141 } 142 143 return $html; 125 144 } 126 145 branches/1.1/lib/widget/sfWidgetFormSchema.class.php
r8408 r8485 281 281 * @param string The field name 282 282 * @param string The field value 283 * @param array An array of HTML attributes to be merged with the current HTML attributes 283 284 * @param array An array of errors for the field 284 285 * 285 286 * @return string A HTML string representing the rendered widget 286 287 */ 287 public function renderField($name, $value = null, $ errors = array())288 public function renderField($name, $value = null, $attributes = array(), $errors = array()) 288 289 { 289 290 if (is_null($widget = $this[$name])) … … 296 297 $clone->setIdFormat($this->options['id_format']); 297 298 298 return $clone->render($this->generateName($name), $value, $clone->getAttributes(), $errors);299 return $clone->render($this->generateName($name), $value, array_merge($clone->getAttributes(), $attributes), $errors); 299 300 } 300 301 … … 340 341 { 341 342 $error = isset($errors[$name]) ? $errors[$name] : array(); 342 $field = $this->renderField($name, $value, $error);343 $field = $this->renderField($name, $value, array(), $error); 343 344 344 345 // don't add a label tag and errors if we embed a form schema branches/1.1/lib/widget/sfWidgetFormSchemaDecorator.class.php
r8408 r8485 188 188 * @see sfWidgetFormSchema 189 189 */ 190 public function renderField($name, $value = null, $ errors = array())191 { 192 return $this->widget->renderField($name, $value, $ errors);190 public function renderField($name, $value = null, $attributes = array(), $errors = array()) 191 { 192 return $this->widget->renderField($name, $value, $attributes, $errors); 193 193 } 194 194 branches/1.1/test/unit/form/sfFormFieldTest.php
r7152 r8485 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(2 2, new lime_output_color());13 $t = new lime_test(24, new lime_output_color()); 14 14 15 15 // widgets … … 73 73 EOF; 74 74 $t->is($f->renderRow(), $output, '->renderRow() renders a row'); 75 75 76 $output = <<<EOF 76 77 <tr> … … 79 80 <li>title error</li> 80 81 </ul> 82 <input type="password" name="article[title]" value="symfony" class="foo" id="title" /></td> 83 </tr> 84 85 EOF; 86 $t->is($f->renderRow(array('class' => 'foo', 'type' => 'password', 'id' => 'title')), $output, '->renderRow() can take an array of HTML attributes as its first argument'); 87 88 $output = <<<EOF 89 <tr> 90 <th><label for="article_title">My title</label></th> 91 <td> <ul class="error_list"> 92 <li>title error</li> 93 </ul> 94 <input type="text" name="article[title]" value="symfony" id="article_title" /></td> 95 </tr> 96 97 EOF; 98 $t->is($f->renderRow(array(), 'My title'), $output, '->renderRow() can take a label name as its second argument'); 99 100 $output = <<<EOF 101 <tr> 102 <th><label for="article_title">Title</label></th> 103 <td> <ul class="error_list"> 104 <li>title error</li> 105 </ul> 81 106 <input type="text" name="article[title]" value="symfony" id="article_title" /><br />help</td> 82 107 </tr> 83 108 84 109 EOF; 85 $t->is($f->renderRow('help'), $output, '->renderRow() can take a help message'); 110 $t->is($f->renderRow(array(), null, 'help'), $output, '->renderRow() can take a help message as its third argument'); 111 86 112 $output = <<<EOF 87 113 <tr> … … 99 125 EOF; 100 126 $t->is($child->renderRow(), $output, '->renderRow() renders a row when the widget has a parent'); 127 101 128 try 102 129 {