Development

Changeset 8756

You must first sign up to be able to contribute.

Changeset 8756

Show
Ignore:
Timestamp:
05/03/08 22:01:36 (6 months ago)
Author:
fabien
Message:

added the possibility to pass HTML attributes for each field when rendering a form or a widget schema

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/widget/sfWidgetFormSchema.class.php

    r8485 r8756  
    333333      $widget = $this[$name]; 
    334334      $value = isset($values[$name]) ? $values[$name] : null; 
     335      $error = isset($errors[$name]) ? $errors[$name] : array(); 
     336      $widgetAttributes = isset($attributes[$name]) ? $attributes[$name] : array(); 
    335337 
    336338      if ($widget instanceof sfWidgetForm && $widget->isHidden()) 
    337339      { 
    338         $hiddenRows[] = $widget->render($this->generateName($name), $value); 
     340        $hiddenRows[] = $widget->render($this->generateName($name), $value, $widgetAttributes); 
    339341      } 
    340342      else 
    341343      { 
    342         $error = isset($errors[$name]) ? $errors[$name] : array(); 
    343         $field = $this->renderField($name, $value, array(), $error); 
     344        $field = $this->renderField($name, $value, $widgetAttributes, $error); 
    344345 
    345346        // don't add a label tag and errors if we embed a form schema 
  • branches/1.1/test/unit/form/sfFormTest.php

    r7154 r8756  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(85, new lime_output_color()); 
     13$t = new lime_test(87, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    247247$t->is($f->renderGlobalErrors(), $output, '->renderGlobalErrors() renders global errors as an HTML list'); 
    248248 
     249// ->render() 
     250$t->diag('->render()'); 
     251$f = new FormTest(); 
     252$f->setValidators(array( 
     253  'id'         => new sfValidatorInteger(), 
     254  'first_name' => new sfValidatorString(array('min_length' => 2)), 
     255  'last_name'  => new sfValidatorString(array('min_length' => 2)), 
     256)); 
     257$f->setWidgets(array( 
     258  'id'         => new sfWidgetFormInputHidden(), 
     259  'first_name' => new sfWidgetFormInput(), 
     260  'last_name'  => new sfWidgetFormInput(), 
     261)); 
     262$f->bind(array( 
     263  'id'         => '1', 
     264  'first_name' => 'Fabien', 
     265  'last_name'  => 'Potencier', 
     266)); 
     267$output = <<<EOF 
     268<tr> 
     269  <th><label for="first_name">First name</label></th> 
     270  <td><input type="text" name="first_name" value="Fabien" id="first_name" /></td> 
     271</tr> 
     272<tr> 
     273  <th><label for="last_name">Last name</label></th> 
     274  <td><input type="text" name="last_name" value="Potencier" id="last_name" /><input type="hidden" name="id" value="1" id="id" /></td> 
     275</tr> 
     276 
     277EOF; 
     278$t->is($f->__toString(), $output, '->__toString() renders the form as HTML'); 
     279$output = <<<EOF 
     280<tr> 
     281  <th><label for="first_name">First name</label></th> 
     282  <td><input type="text" name="first_name" value="Fabien" class="foo" id="first_name" /></td> 
     283</tr> 
     284<tr> 
     285  <th><label for="last_name">Last name</label></th> 
     286  <td><input type="text" name="last_name" value="Potencier" id="last_name" /><input type="hidden" name="id" value="1" id="id" /></td> 
     287</tr> 
     288 
     289EOF; 
     290$t->is($f->render(array('first_name' => array('class' => 'foo'))), $output, '->render() renders the form as HTML'); 
     291 
    249292// ->embedForm() 
    250293$t->diag('->embedForm()'); 
  • branches/1.1/test/unit/widget/sfWidgetFormSchemaTest.php

    r8408 r8756  
    309309    <li>Too short</li> 
    310310  </ul> 
    311 <input class="foo1" type="text" name="article[first_name]" id="id_article_first_name" /></td> 
     311<input class="foo" type="text" name="article[first_name]" value="Fabien" id="id_article_first_name" /></td> 
    312312</tr> 
    313313<tr> 
    314314  <th><label style="padding: 5px" for="id_article_last_name">Last name</label></th> 
    315   <td><input type="text" name="article[last_name]" id="id_article_last_name" /><input type="hidden" name="article[id]" id="article_id" /></td> 
     315  <td><input type="text" name="article[last_name]" value="Potencier" class="bar" id="id_article_last_name" /><input type="hidden" name="article[id]" id="article_id" /></td> 
    316316</tr> 
    317317 
    318318EOF; 
    319 $rendered = $w->render(null, array('w1' => 'Fabien', 'w2' => 'Potencier'), array(), array('first_name' => 'Too short', 'Global error message', 'id' => 'Required')); 
     319$rendered = $w->render(null, array('first_name' => 'Fabien', 'last_name' => 'Potencier'), array('first_name' => array('class' => 'foo'), 'last_name' => array('class' => 'bar')), array('first_name' => 'Too short', 'Global error message', 'id' => 'Required')); 
    320320$t->is($rendered, $expected, '->render() renders a schema to HTML'); 
    321321