I have this schema:
propel:
autor:
id: ~
nombre: { type: varchar, size: 255, required: true }
libro:
id: ~
autor_id: { type: integer, size: 11, foreignTable: autor,
foreignReference: id}
titulo: { type: varchar, size: 255 }
paginas: { type: varchar, size: 255, required: true }
and this form class:
class AutorForm extends BaseAutorForm
{
public function configure()
{
$this->embedRelation('Libro');
}
public function foo()
{
$this->validatorSchema['Libro']['newLibro1']['paginas'] = new
sfValidatorPass();
return $this;
}
}
I’m calling foo() after the bind() (inside processForm()).
After submiting the Auto-Libro form, if I don’t insert anything in the
field ‘paginas’ of the first embedded form (Libro), it shows
“Required”.
But.. why if paginas has a validator-pass?
EDIT: after matt’s answer, this is my code:
var_dump($this->embeddedForms['Libro']->validatorSchema['newLibro1']['paginas']);
$this->embeddedForms['Libro']->validatorSchema['newLibro1']['paginas'] = new sfValidatorPass(array('required' => false));
var_dump($this->embeddedForms['Libro']->validatorSchema['newLibro1']['paginas']);
It prints this:
object(sfValidatorString)[152]
protected 'requiredOptions' =>
array
empty
protected 'defaultMessages' =>
array
'required' => string 'Required.' (length=9)
'invalid' => string 'Invalid.' (length=8)
'max_length' => string '"%value%" is too long (%max_length% characters max).' (length=52)
'min_length' => string '"%value%" is too short (%min_length% characters min).' (length=53)
protected 'defaultOptions' =>
array
'required' => boolean true
'trim' => boolean false
'empty_value' => string '' (length=0)
'max_length' => null
'min_length' => null
protected 'messages' =>
array
'required' => string 'Required.' (length=9)
'invalid' => string 'Invalid.' (length=8)
'max_length' => string '"%value%" is too long (%max_length% characters max).' (length=52)
'min_length' => string '"%value%" is too short (%min_length% characters min).' (length=53)
protected 'options' =>
array
'required' => boolean true
'trim' => boolean false
'empty_value' => string '' (length=0)
'max_length' => int 255
'min_length' => null
object(sfValidatorPass)[196]
protected 'requiredOptions' =>
array
empty
protected 'defaultMessages' =>
array
'required' => string 'Required.' (length=9)
'invalid' => string 'Invalid.' (length=8)
protected 'defaultOptions' =>
array
'required' => boolean true
'trim' => boolean false
'empty_value' => null
protected 'messages' =>
array
'required' => string 'Required.' (length=9)
'invalid' => string 'Invalid.' (length=8)
protected 'options' =>
array
'required' => boolean false <<<<<<<<<<<< FALSE <<<<<<<<<<<<<<<<<<
'trim' => boolean false
'empty_value' => null
The problem is still the same: when i try to submit the form, the field ‘paginas’ is still required. Why?
sf 1.4/propel 1.6
Javi
Almost all validators, including the sfValidatorPass, default to required=true.
I believe the sfValidatorPass doesn’t mean “it always passes validation” it means “pass the submitted value through without cleaning it or checking anything.”
So I think you can just do