|  | 
  bartb - 2010-09-21 11:48:12Hi! Thanks for your superb class!I have a question about DependantValidation. Is it possible to make an input field dependant of multiple other input fields? I've tried to enter an array in the DependantValidation attribute, but that didn't do the job.
 thanks, Bart
  Manuel Lemos - 2010-09-22 01:57:17 - In reply to message 1 from bartbDependent validation is just for determine whether an input is going to be validated or not depending on the value of another input.
 Is that what you want or you want to make the value of an input depend on the values of other inputs?
  bartb - 2010-09-22 05:33:16 - In reply to message 2 from Manuel LemosThanks for your reply. I mean the first. Let me give an example:I have a set of radiobuttons named a, b and c and a text field. What I want to do is validate the text field if radiobutton a or b is checked, but not when c is checked. Is this possible?
 Thanks, Bart
  Manuel Lemos - 2010-09-22 06:20:25 - In reply to message 3 from bartbYes, that is easy because radio buttons have boolean values: checked or not checked. 
You just need to set the DependentValidation property of the input you want to validate conditionally to the ID of the radio button you want it to be dependent.
 
Take a look at the test_dependent_validation.php example script:
 phpclasses.org/browse/file/19360.ht ...
  bartb - 2010-09-22 06:45:33 - In reply to message 4 from Manuel LemosThanks, but that is not quite what i meant. In your example you have 1 checkbox and 1 textfield. That is clear to me.
 
 But what if you have 3 radiobuttons as a set and 1 textfield and the textfield must be validated only if radio 1 or 2 is checked, but not when checkbox 3 is checked. So, the textfield is dependant of 2 radiobuttons.
 Can I configure like this:
 
 "DependantValidation" => array('radiobutton1', 'radiobutton2'),
 
 thanks for your effort, Bart
  Manuel Lemos - 2010-09-22 08:20:46 - In reply to message 5 from bartbOh, I see. In that case you need to implement a custom input plug-in class that checks all the dependent inputs like this:
 
 class form_custom_dependent_validation_class extends form_custom_class
 {
 var $inputs = array();
 
 Function AddInput(&$form, $arguments)
 {
 if(!IsSet($arguments['DependentValidations'])
 || GetType($arguments['DependentValidations']) != 'array'
 || count($this->inputs = $arguments['DependentValidations']) == 0)
 return('it was not specified the list of dependent validation inputs');
 return('');
 }
 
 Function GetJavascriptCheckedState(&$form, $form_object)
 {
 $javascript = '';
 $ti = count($this->inputs);
 for($i = 0; $i < $ti; ++$i)
 {
 if(strlen($js = $form->GetJavascriptCheckedState($form_object, $this->inputs[$i])) == 0)
 return('');
 if($i > 0)
 $javascript .= '|| ';
 $javascript .= $js;
 }
 return($javascript);
 }
 
 Function GetCheckedState(&$form)
 {
 $ti = count($this->inputs);
 for($i = 0; $i < $ti; ++$i)
 {
 if($form->GetCheckedState($this->inputs[$i]))
 return(1);
 }
 return(0);
 }
 
 Function ValidateInput(&$form)
 {
 return('');
 }
 };
 
 Then you add the custom input like this:
 
 $form->AddInput(array(
 'TYPE'=>'custom',
 'ID'=>'custom_condition',
 'NAME'=>'custom_condition',
 'CustomClass'=>'form_custom_dependent_validation_class',
 'DependentValidations'=>array(
 'radio_1',
 'radio_2',
 )
 ));
 
  bartb - 2010-09-22 08:59:32 - In reply to message 6 from Manuel Lemoswow, superb!thanks a lot for your (quick!) solution.
 |