dans mon form general productForm.class.php je fait un
$this->embedForm('newNomenclature', $form);
pour ajouter une nouvelle nomenclature en formulaire imbriqué,
ensuite dans nomenclatureForm.class.php je fait
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| unset($this->validatorSchema['products_list']);
unset($this->widgetSchema['products_list']);
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'nomenclature' => new sfWidgetFormInputFile(),
));
$this->widgetSchema->setLabels(array(
'nomenclature' => 'File',
));
$this->setValidators(array(
'id' => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'id', 'required' => false)),
'nomenclature' => new sfValidatorFile(array(
'path' => sfConfig::get('sf_upload_dir').'/manufacturing_files',
'required' => false
))
)); |
et j'appelle ensuite
$this->mergePostValidator(new NomenclatureValidatorSchema());
et dans mon NomenclatureValidatorSchema.class.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| protected function doClean($values)
{
$errorSchema = new sfValidatorErrorSchema($this);
foreach($values as $key => $value)
{
$errorSchemaLocal = new sfValidatorErrorSchema($this);
if (!$value['nomenclature'] ) {
unset($values[$key]);
}
// some error for this embedded-form
if (count($errorSchemaLocal))
{
$errorSchema->addError($errorSchemaLocal, (string) $key);
}
}
// throws the error for the main form
if (count($errorSchema))
{
throw new sfValidatorErrorSchema($this, $errorSchema);
}
return $values;
} |
Partager