Wouldn't it be good too to validate them as not required then use an
sfValidatorCallback using $this(form)->setPostValidator(new
sfValidatorCallback()) ? This is used when one field validation depends on
some others.
Another way is to make the $required of your validators being options, using
$this->getOption(). Then where you create your instance you'll give right
options, and in the configure method you'll call a configureValidators
method which will act according to the options.
The problem will be about message errors.
I've done this to control which fields to show or not according to the
action, then I added some other configuration options (hide, etc). This
needs to somehow overload the configuration class of the admin-gens (I have
used doctrine one).
Or you can add method for state methods to your form class (and why not, in
it, hardcoding the option array given to the form.
Another way is to make the form maleable : in fact it is, you can call
$form->getValidator('my_required_widget')->setOption('required', false).
Then after instanciation, just call a class (which will contains all the
different configuration strategies possible-needed for this particular form)
static method which will handle the correct setting of the form.
There are plenty ways of doing so, to say it clearly :-)
Before Printing, Think about Your Environmental Responsibility!
Avant d'Imprimer, Pensez à Votre Responsabilitée Environnementale!
On Sat, May 22, 2010 at 5:36 PM, Johannes <
[email protected]> wrote:
> You need to exchange the validator schema of the form with your own
> validator schema class, and overwrite the preClean() method there.
>
> This is the only way to ensure that your form behaves the same whether
> it is used standalone or embedded elsewhere.
>
> Johannes
>
> On 21 Mai, 15:04, kadia <[email protected]> wrote:
> > I want to set a validor for a field on configure (), but the field can
> > be required or not, it depends on the value of another field. Now I
> > need set the condition following the value of that filed but I can
> > find the good function, for having that value.
> >
> > I have to use it one configure() function.
> >
> > class FormuleForm extends BaseFormuleForm
> > {
> >
> > public function configure()
> > {
> >
> > /// I have tried this, but it's not ok
> >
> > if ($this->getValue('idsitecompactage')==2)
> > {$this->validatorSchema['commentaire']=new
> > sfValidatorString(array('required' => true));
> > }
> > *******
> >
> > }
> > }
> >
> > --
> > If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
> >
> > You received this message because you are subscribed to the Google
> > Groups "symfony users" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]<symfony-users%[email protected]>
> > For more options, visit this group athttp://
> groups.google.com/group/symfony-users?hl=en
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<symfony-users%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en