Changeset 6944
- Timestamp:
- 01/05/08 13:51:12 (11 months ago)
- Files:
-
- branches/1.1/lib/form/sfForm.class.php (modified) (2 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php (modified) (3 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseArticleForm.class.php (modified) (3 diffs)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php (modified) (1 diff)
- branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php (modified) (1 diff)
- branches/1.1/test/unit/form/sfFormTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/form/sfForm.class.php
r6748 r6944 275 275 276 276 /** 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 /** 277 287 * Sets the validator schema associated with this form. 278 288 * … … 294 304 { 295 305 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)); 296 316 } 297 317 branches/1.1/lib/plugins/sfPropelPlugin/data/generator/sfPropelForm/default/template/sfPropelFormGeneratedTemplate.php
r6873 r6944 13 13 public function setup() 14 14 { 15 $this->setWidget Schema(new sfWidgetFormSchema(array(15 $this->setWidgets(array( 16 16 <?php foreach ($this->table->getColumns() as $column): ?> 17 17 '<?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) ?>), … … 20 20 '<?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')))), 21 21 <?php endforeach; ?> 22 )) );22 )); 23 23 24 $this->setValidator Schema(new sfValidatorSchema(array(24 $this->setValidators(array( 25 25 <?php foreach ($this->table->getColumns() as $column): ?> 26 26 '<?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) ?>), … … 29 29 '<?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')))), 30 30 <?php endforeach; ?> 31 )) );31 )); 32 32 33 33 $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 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'id' => new sfWidgetFormInputHidden(), 16 16 'title' => new sfWidgetFormInput(), … … 21 21 'end_date' => new sfWidgetFormDateTime(), 22 22 'book_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getBookChoices')))), 23 )) );23 )); 24 24 25 $this->setValidator Schema(new sfValidatorSchema(array(25 $this->setValidators(array( 26 26 'id' => new sfValidatorInteger(array('required' => false)), 27 27 'title' => new sfValidatorString(), … … 32 32 'end_date' => new sfValidatorDateTime(array('required' => false)), 33 33 'book_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getBookIdentifierChoices')), 'required' => false)), 34 )) );34 )); 35 35 36 36 $this->widgetSchema->setNameFormat('article[%s]'); branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorArticleForm.class.php
r6882 r6944 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'author_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getAuthorChoices')))), 16 16 'article_id' => new sfWidgetFormSelect(array('choices' => new sfCallable(array($this, 'getArticleChoices')))), 17 17 'id' => new sfWidgetFormInputHidden(), 18 )) );18 )); 19 19 20 $this->setValidator Schema(new sfValidatorSchema(array(20 $this->setValidators(array( 21 21 'author_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getAuthorIdentifierChoices')), 'required' => false)), 22 22 'article_id' => new sfValidatorChoice(array('choices' => new sfCallable(array($this, 'getArticleIdentifierChoices')), 'required' => false)), 23 23 'id' => new sfValidatorInteger(array('required' => false)), 24 )) );24 )); 25 25 26 26 $this->widgetSchema->setNameFormat('author_article[%s]'); branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseAuthorForm.class.php
r6882 r6944 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'id' => new sfWidgetFormInputHidden(), 16 16 'name' => new sfWidgetFormInput(), 17 )) );17 )); 18 18 19 $this->setValidator Schema(new sfValidatorSchema(array(19 $this->setValidators(array( 20 20 'id' => new sfValidatorInteger(array('required' => false)), 21 21 'name' => new sfValidatorString(array('required' => false)), 22 )) );22 )); 23 23 24 24 $this->widgetSchema->setNameFormat('author[%s]'); branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseBookForm.class.php
r6882 r6944 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'id' => new sfWidgetFormInputHidden(), 16 16 'name' => new sfWidgetFormInput(), 17 )) );17 )); 18 18 19 $this->setValidator Schema(new sfValidatorSchema(array(19 $this->setValidators(array( 20 20 'id' => new sfValidatorInteger(array('required' => false)), 21 21 'name' => new sfValidatorString(array('required' => false)), 22 )) );22 )); 23 23 24 24 $this->widgetSchema->setNameFormat('book[%s]'); branches/1.1/lib/plugins/sfPropelPlugin/test/functional/fixtures/lib/form/base/BaseCategoryForm.class.php
r6882 r6944 12 12 public function setup() 13 13 { 14 $this->setWidget Schema(new sfWidgetFormSchema(array(14 $this->setWidgets(array( 15 15 'id' => new sfWidgetFormInputHidden(), 16 16 'name' => new sfWidgetFormInput(), 17 )) );17 )); 18 18 19 $this->setValidator Schema(new sfValidatorSchema(array(19 $this->setValidators(array( 20 20 'id' => new sfValidatorInteger(array('required' => false)), 21 21 'name' => new sfValidatorString(array('required' => false)), 22 )) );22 )); 23 23 24 24 $this->widgetSchema->setNameFormat('category[%s]'); branches/1.1/test/unit/form/sfFormTest.php
r6748 r6944 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test( 68, new lime_output_color());13 $t = new lime_test(74, new lime_output_color()); 14 14 15 15 class FormTest extends sfForm … … 105 105 $t->ok($f->isMultipart(),'->isMultipart() returns true if the form needs a multipart form'); 106 106 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 107 137 // ArrayAccess interface 108 138 $t->diag('ArrayAccess interface');