Development

Changeset 6944

You must first sign up to be able to contribute.

Changeset 6944

Show
Ignore:
Timestamp:
01/05/08 13:51:12 (11 months ago)
Author:
fabien
Message:

added sfForm::setValidators() and sfForm::setWidgets()

Files:

Legend:

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

    r6748 r6944  
    275275 
    276276  /** 
     277   * Sets the validators associated with this form. 
     278   * 
     279   * @param array An array of named validators 
     280   */ 
     281  public function setValidators(array $validators) 
     282  { 
     283    $this->setValidatorSchema(new sfValidatorSchema($validators)); 
     284  } 
     285 
     286  /** 
    277287   * Sets the validator schema associated with this form. 
    278288   * 
     
    294304  { 
    295305    return $this->validatorSchema; 
     306  } 
     307 
     308  /** 
     309   * Sets the widgets associated with this form. 
     310   * 
     311   * @param array An array of named widgets 
     312   */ 
     313  public function setWidgets(array $widgets) 
     314  { 
     315    $this->setWidgetSchema(new sfWidgetFormSchema($widgets)); 
    296316  } 
    297317 
  • branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php

    r6873 r6944  
    1313  public function setup() 
    1414  { 
    15     $this->setWidgetSchema(new sfWidgetFormSchema(array( 
     15    $this->setWidgets(array( 
    1616<?php foreach ($this->table->getColumns() as $column): ?> 
    1717      '<?php echo strtolower($column->getColumnName()) ?>'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($column->getColumnName())) ?> => new <?php echo $this->getWidgetClassForColumn($column) ?>(<?php echo $this->getWidgetOptionsForColumn($column) ?>), 
     
    2020      '<?php echo $tables['relatedTable']->getName() ?>_list'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($tables['relatedTable']->getName().'_list')) ?> => new sfWidgetFormSelectMany(array('choices' => new sfCallable(array($this, 'get<?php echo $tables['relatedTable']->getPhpName() ?>Choices')))), 
    2121<?php endforeach; ?> 
    22     )))
     22    ))
    2323 
    24     $this->setValidatorSchema(new sfValidatorSchema(array( 
     24    $this->setValidators(array( 
    2525<?php foreach ($this->table->getColumns() as $column): ?> 
    2626      '<?php echo strtolower($column->getColumnName()) ?>'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($column->getColumnName())) ?> => new <?php echo $this->getValidatorClassForColumn($column) ?>(<?php echo $this->getValidatorOptionsForColumn($column) ?>), 
     
    2929      '<?php echo $tables['relatedTable']->getName() ?>_list'<?php echo str_repeat(' ', $this->getColumnNameMaxLength() - strlen($tables['relatedTable']->getName().'_list')) ?> => new sfValidatorChoiceMany(array('choices' => new sfCallable(array($this, 'get<?php echo $tables['relatedTable']->getPhpName() ?>IdentifierChoices')))), 
    3030<?php endforeach; ?> 
    31     )))
     31    ))
    3232 
    3333    $this->widgetSchema->setNameFormat('<?php echo $this->table->getName() ?>[%s]'); 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php

    r6882 r6944  
    1212  public function setup() 
    1313  { 
    14     $this->setWidgetSchema(new sfWidgetFormSchema(array( 
     14    $this->setWidgets(array( 
    1515      'id'          => new sfWidgetFormInputHidden(), 
    1616      'title'       => new sfWidgetFormInput(), 
     
    2121      'end_date'    => new sfWidgetFormDateTime(), 
    2222      'book_id'     => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getBookChoices')))), 
    23     )))
     23    ))
    2424 
    25     $this->setValidatorSchema(new sfValidatorSchema(array( 
     25    $this->setValidators(array( 
    2626      'id'          => new sfValidatorInteger(array('required' => false)), 
    2727      'title'       => new sfValidatorString(), 
     
    3232      'end_date'    => new sfValidatorDateTime(array('required' => false)), 
    3333      'book_id'     => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getBookIdentifierChoices')), 'required' => false)), 
    34     )))
     34    ))
    3535 
    3636    $this->widgetSchema->setNameFormat('article[%s]'); 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php

    r6882 r6944  
    1212  public function setup() 
    1313  { 
    14     $this->setWidgetSchema(new sfWidgetFormSchema(array( 
     14    $this->setWidgets(array( 
    1515      'author_id'  => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getAuthorChoices')))), 
    1616      'article_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getArticleChoices')))), 
    1717      'id'         => new sfWidgetFormInputHidden(), 
    18     )))
     18    ))
    1919 
    20     $this->setValidatorSchema(new sfValidatorSchema(array( 
     20    $this->setValidators(array( 
    2121      'author_id'  => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getAuthorIdentifierChoices')), 'required' => false)), 
    2222      'article_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getArticleIdentifierChoices')), 'required' => false)), 
    2323      'id'         => new sfValidatorInteger(array('required' => false)), 
    24     )))
     24    ))
    2525 
    2626    $this->widgetSchema->setNameFormat('author_article[%s]'); 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php

    r6882 r6944  
    1212  public function setup() 
    1313  { 
    14     $this->setWidgetSchema(new sfWidgetFormSchema(array( 
     14    $this->setWidgets(array( 
    1515      'id'   => new sfWidgetFormInputHidden(), 
    1616      'name' => new sfWidgetFormInput(), 
    17     )))
     17    ))
    1818 
    19     $this->setValidatorSchema(new sfValidatorSchema(array( 
     19    $this->setValidators(array( 
    2020      'id'   => new sfValidatorInteger(array('required' => false)), 
    2121      'name' => new sfValidatorString(array('required' => false)), 
    22     )))
     22    ))
    2323 
    2424    $this->widgetSchema->setNameFormat('author[%s]'); 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php

    r6882 r6944  
    1212  public function setup() 
    1313  { 
    14     $this->setWidgetSchema(new sfWidgetFormSchema(array( 
     14    $this->setWidgets(array( 
    1515      'id'   => new sfWidgetFormInputHidden(), 
    1616      'name' => new sfWidgetFormInput(), 
    17     )))
     17    ))
    1818 
    19     $this->setValidatorSchema(new sfValidatorSchema(array( 
     19    $this->setValidators(array( 
    2020      'id'   => new sfValidatorInteger(array('required' => false)), 
    2121      'name' => new sfValidatorString(array('required' => false)), 
    22     )))
     22    ))
    2323 
    2424    $this->widgetSchema->setNameFormat('book[%s]'); 
  • branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php

    r6882 r6944  
    1212  public function setup() 
    1313  { 
    14     $this->setWidgetSchema(new sfWidgetFormSchema(array( 
     14    $this->setWidgets(array( 
    1515      'id'   => new sfWidgetFormInputHidden(), 
    1616      'name' => new sfWidgetFormInput(), 
    17     )))
     17    ))
    1818 
    19     $this->setValidatorSchema(new sfValidatorSchema(array( 
     19    $this->setValidators(array( 
    2020      'id'   => new sfValidatorInteger(array('required' => false)), 
    2121      'name' => new sfValidatorString(array('required' => false)), 
    22     )))
     22    ))
    2323 
    2424    $this->widgetSchema->setNameFormat('category[%s]'); 
  • branches/1.1/test/unit/form/sfFormTest.php

    r6748 r6944  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(68, new lime_output_color()); 
     13$t = new lime_test(74, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    105105$t->ok($f->isMultipart(),'->isMultipart() returns true if the form needs a multipart form'); 
    106106 
     107// ->setValidators() ->setValidatorSchema() ->getValidatorSchema() 
     108$t->diag('->setValidators() ->setValidatorSchema() ->getValidatorSchema()'); 
     109$f = new FormTest(); 
     110$validators = array( 
     111  'first_name' => new sfValidatorPass(), 
     112  'last_name' => new sfValidatorPass(), 
     113); 
     114$validatorSchema = new sfValidatorSchema($validators); 
     115$f->setValidatorSchema($validatorSchema); 
     116$t->is_deeply($f->getValidatorSchema(), $validatorSchema, '->setValidatorSchema() sets the current validator schema'); 
     117$f->setValidators($validators); 
     118$schema = $f->getValidatorSchema(); 
     119$t->is_deeply($schema['first_name'], $validators['first_name'], '->setValidators() sets field validators'); 
     120$t->is_deeply($schema['last_name'], $validators['last_name'], '->setValidators() sets field validators'); 
     121 
     122// ->setWidgets() ->setWidgetSchema() ->getWidgetSchema() 
     123$t->diag('->setWidgets() ->setWidgetSchema() ->getWidgetSchema()'); 
     124$f = new FormTest(); 
     125$widgets = array( 
     126  'first_name' => new sfWidgetFormInput(), 
     127  'last_name'  => new sfWidgetFormInput(), 
     128); 
     129$widgetSchema = new sfWidgetFormSchema($widgets); 
     130$f->setWidgetSchema($widgetSchema); 
     131$t->is_deeply($f->getWidgetSchema(), $widgetSchema, '->setWidgetSchema() sets the current widget schema'); 
     132$f->setWidgets($widgets); 
     133$schema = $f->getWidgetSchema(); 
     134$t->is_deeply($schema['first_name'], $widgets['first_name'], '->setWidgets() sets field widgets'); 
     135$t->is_deeply($schema['last_name'], $widgets['last_name'], '->setWidgets() sets field widgets'); 
     136 
    107137// ArrayAccess interface 
    108138$t->diag('ArrayAccess interface');