Changeset 11383
- Timestamp:
- 09/09/08 00:06:56 (5 years ago)
- Files:
-
- plugins/sfFormtasticPlugin/trunk/config/app.yml (added)
- plugins/sfFormtasticPlugin/trunk/lib/form/sfFormtasticBase.class.php (modified) (1 diff)
- plugins/sfFormtasticPlugin/trunk/lib/validator/sfValidatornatorErrorSchema.class.php (modified) (1 diff)
- plugins/sfFormtasticPlugin/trunk/test/unit/sfFormtasticBaseTest.php (modified) (2 diffs)
- plugins/sfFormtasticPlugin/trunk/test/unit/sfValidatornatorErrorSchemaTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfFormtasticPlugin/trunk/lib/form/sfFormtasticBase.class.php
r11336 r11383 104 104 * @see sfForm 105 105 */ 106 public function bind(array $taintedValues = null, array $taintedFiles = null) 107 { 108 parent::bind($taintedValues, $taintedFiles); 109 110 // replace sfValidatorErrorSchema 111 $this->errorSchema = new sfValidatornatorErrorSchema($this->validatorSchema, $this->errorSchema); 112 } 113 114 /** 115 * @see sfForm 116 */ 106 117 public function render($attributes = array()) 107 118 { plugins/sfFormtasticPlugin/trunk/lib/validator/sfValidatornatorErrorSchema.class.php
r10206 r11383 14 14 class sfValidatornatorErrorSchema extends sfValidatornatorErrorSchemaBase 15 15 { 16 /** 17 * Returns the current error schema serialized as JSON. 18 * 19 * @return string 20 */ 21 public function toJson() 22 { 23 $callable = sfConfig::get('app_sf_formtastic_plugin_json_encode_callable', 'json_encode'); 24 if (!is_callable($callable)) 25 { 26 throw new RuntimeException(sprintf('The json_encoder_callable "%s" does not exist.', var_export($callable, true))); 27 } 28 29 // build an array of scalars 30 $data = array(); 31 foreach ($this->globalErrors as $error) 32 { 33 if (!isset($data['_global'])) 34 { 35 $data['_global'] = array(); 36 } 37 $data['_global'][] = $error->getMessage(); 38 } 39 foreach ($this->getNamedErrors() as $name => $error) 40 { 41 if (!isset($data[$name])) 42 { 43 $data[$name] = array(); 44 } 45 $data[$name][] = $error->getMessage(); 46 } 47 48 return call_user_func($callable, $data); 49 } 16 50 } plugins/sfFormtasticPlugin/trunk/test/unit/sfFormtasticBaseTest.php
r11337 r11383 3 3 include dirname(__FILE__).'/../bootstrap/unit.php'; 4 4 5 $t = new lime_test( 19, new lime_output_color);5 $t = new lime_test(21, new lime_output_color); 6 6 7 7 sfForm::enableCSRFProtection('secretastic'); … … 58 58 $form->setIdFormat(false); 59 59 $t->unlike($form->render(), '/id="/', '"->setIdFormat(false)" removes id attribute'); 60 61 $t->diag('->bind()'); 62 $form->bind(array('name' => 'xyztastic')); 63 $t->isa_ok($form->getErrorSchema(), 'sfValidatornatorErrorSchema', '->bind() copies native error schema'); 64 $t->is(count($form->getErrorSchema()), 1, '->bind() copies the correct number of errors');