remove validation from particular elements, all container or group in form

Notice: This thread is very old.
richard
Member | 60
+
0
-

Toggle is handy but how can I also remove validation from form elements, container or group?

<?php
$form->addCheckbox('Send me a postcard')
	->addCondition(Form::EQUAL, TRUE)
        ->toggle('address');
$address = $form->addContainer('address');
$address->add...
...
now bunch of items and validation rules
...
?>
petr.pavel
Member | 504
+
0
-

Hi Richard,
to be sure I understand, you want validation rules for fields within a container to trigger only if the container is visible, right?

I guess you should think the other way around, not disabling triggers but enabling them on a condition.

$sendField = $form->addCheckbox('Send me a postcard');
$sendField->addCondition(Form::EQUAL, TRUE)->toggle('address');

$address = $form->addContainer('address');
$address->addText(...)->addConditionOn($sendField,  Form::EQUAL, TRUE)
  ->addRule(....)
richard
Member | 60
+
0
-

Hi,

this is more detailed example of what I am trying to do:

<?php
$form->addRadioList('travel','Prefered way of travel:', array('by boat','on foot'))
	->setRequired();
$form['travel']->addCondition(Form::EQUAL, 0)->toggle('ship');
............
$ship->addRadioList('boat','Prefered boat:', array('yacht','canoe'))
	->addConditionOn($form['travel'],Form::EQUAL, 0)->setRequired();
$ship['type']->addCondition(Form::EQUAL, 0)->toggle('yacht');
............
$ship->addRadioList('yacht', 'Prefered yacht:', array('motor','sail'))
	->addConditionOn($ship['type'],Form::EQUAL, 0)->setRequired();
............
?>

Obviously, I do not want to mess around with non-relevant questions in form but when user starts filling it out (i.e. clicks few things but then he gets back to ‘on foot’) then all the non-relevant stuff still gets validated.

Is there a way?

Last edited by richard (2011-09-12 18:02)

voda
Member | 561
+
0
-

Hi, try adding more conditions:

<?php
$ship['yacht']->addRadioList('yacht', 'Prefered yacht:', array('motor','sail'))
	->addConditionOn($form['travel'],Form::EQUAL, 0)
        ->addConditionOn($ship['type'],Form::EQUAL, 0)
	->setRequired();
?>
richard
Member | 60
+
0
-

To me it looks that addConditionOn works only with items from the same container.

The following does not work:

<?php
$containerA['itemA']->addConditionOn($containerB['itemB'],Form::EQUAL, 0);
?>

Maybe someone will verify this.