not empty validation and javascript

keianrad

Member
There is a filed with empty validation plugin the that get hide/show based on another filed value.

The problem that when the filed is hide, the validation doesn't allow to submit the form with empty filed.

I need to run the validation only when it's not hide. Is there only solution for that?
 
You have to add a "Condition" for the validation, which checks the form data value for the element that controls whether it is hidden. So if you have (say) yourtable___yesno which if set to 0 hides the element with the validation, your Condition PHP would look like:

return $formModel->formData['yourtable___yesno_raw'] != '0';

So that'll return true is 'yesno' is not 0, and the validation will run.

I'm working atm on some code to integrate into the JS events, to automate this process. So there will (at some point) be an option in all validations to "Don't validate if hidden by JS", which will automatically handle this.

-- hugh
 
Thank you Hugh, But my filed is a database join list and it return id.

I tried this code but it doesn't work:

return $formModel->formData['app_assessment___subject_id'] >= '93';
 
Thank you, I had the same probleme and it works for me, but without '' around the number
return $formModel->formData['app_assessment___subject_id'] >= 93;
 
Depending on how the element is set up, if it's a join element, it can be an array, so ...

Code:
$subjectId = $formModel->formData['app_assessment___subject_id'];
$subjectId = is_array($subjectId) ? $subjectId[0] : $subjectId;
return $subjectId >= '93';

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top