Development

Changeset 8485

You must first sign up to be able to contribute.

Changeset 8485

Show
Ignore:
Timestamp:
04/16/08 19:41:41 (6 months ago)
Author:
fabien
Message:

changed the sfFormField::renderRow() signature to be able to add HTML attributes, change the label and the help message (closes #3336)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/form/sfFormField.class.php

    r8408 r8485  
    7171   * The formatted row will use the parent widget schema formatter. 
    7272   * 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) 
    7678   * 
    7779   * @return string The formatted row 
    7880   */ 
    79   public function renderRow($help = ''
     81  public function renderRow($attributes = array(), $label = null, $help = null
    8082  { 
    8183    if (is_null($this->parent)) 
     
    8486    } 
    8587 
    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); 
    8789 
    8890    $error = $this->error instanceof sfValidatorErrorSchema ? $this->error->getGlobalErrors() : $this->error; 
    8991 
    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%' => '')); 
    9195  } 
    9296 
     
    113117   * Returns the label tag. 
    114118   * 
     119   * @param  string The label name (not null to override the current value) 
     120   * 
    115121   * @return string The label tag 
    116122   */ 
    117   public function renderLabel(
     123  public function renderLabel($label = null
    118124  { 
    119125    if (is_null($this->parent)) 
     
    122128    } 
    123129 
    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; 
    125144  } 
    126145 
  • branches/1.1/lib/widget/sfWidgetFormSchema.class.php

    r8408 r8485  
    281281   * @param  string  The field name 
    282282   * @param  string  The field value 
     283   * @param  array   An array of HTML attributes to be merged with the current HTML attributes 
    283284   * @param  array   An array of errors for the field 
    284285   * 
    285286   * @return string  A HTML string representing the rendered widget 
    286287   */ 
    287   public function renderField($name, $value = null, $errors = array()) 
     288  public function renderField($name, $value = null, $attributes = array(), $errors = array()) 
    288289  { 
    289290    if (is_null($widget = $this[$name])) 
     
    296297    $clone->setIdFormat($this->options['id_format']); 
    297298 
    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); 
    299300  } 
    300301 
     
    340341      { 
    341342        $error = isset($errors[$name]) ? $errors[$name] : array(); 
    342         $field = $this->renderField($name, $value, $error); 
     343        $field = $this->renderField($name, $value, array(), $error); 
    343344 
    344345        // don't add a label tag and errors if we embed a form schema 
  • branches/1.1/lib/widget/sfWidgetFormSchemaDecorator.class.php

    r8408 r8485  
    188188   * @see sfWidgetFormSchema 
    189189   */ 
    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); 
    193193  } 
    194194 
  • branches/1.1/test/unit/form/sfFormFieldTest.php

    r7152 r8485  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(22, new lime_output_color()); 
     13$t = new lime_test(24, new lime_output_color()); 
    1414 
    1515// widgets 
     
    7373EOF; 
    7474$t->is($f->renderRow(), $output, '->renderRow() renders a row'); 
     75 
    7576$output = <<<EOF 
    7677<tr> 
     
    7980    <li>title error</li> 
    8081  </ul> 
     82<input type="password" name="article[title]" value="symfony" class="foo" id="title" /></td> 
     83</tr> 
     84 
     85EOF; 
     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 
     97EOF; 
     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> 
    81106<input type="text" name="article[title]" value="symfony" id="article_title" /><br />help</td> 
    82107</tr> 
    83108 
    84109EOF; 
    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 
    86112$output = <<<EOF 
    87113<tr> 
     
    99125EOF; 
    100126$t->is($child->renderRow(), $output, '->renderRow() renders a row when the widget has a parent'); 
     127 
    101128try 
    102129{