I have an unbound form with two fields that i would like to validate. I would like to use the built in NotBlank on both fields and my two custom validators MyFile and *UploadConstraints *. The problem is i can get all three to work together. The UploadConstraints is called before the NotBlanks() and if i comment the UploadConstraints the attachment constraints does not fire, i used UploadConstraints to refer to both fields.
$builder
->add('country', 'entity',array(
'class' => 'WarrDigicelBundle:Country',
'property' => 'name',// display of countries
'label' => 'Country:',
'empty_value' => '',
'empty_data' => null,
'required' => false,
'constraints' => new NotBlank(),
))
->add('attachment', 'file',array(
'label' => 'Upload:',
'required' => false,
'constraints' => new NotBlank(),
'constraints' => array( new Constraints\MyFile())
))
->add('Upload File', 'submit')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => null,
'cascade_validation' => true,
'constraints' => array( new Constraints\UploadConstraints())
));
}