Buy Now
Sign in

If Then style validation

milton.martinez , March 27 2014
Dear Support,

I'm using CFv5. Is it possible to do "If Then style validation"? The problem I have to solve is according to the next situation:

I have two components, one dropdown and one text box. When the user choices YES in the dropdown then the text box has to be required. If the user choices NO then the field has to be blank and read only.

How can I do this?

Thanks in advance
Hi Milton,

Yes, so you can simply use the "events" section under the "Dropdown" settings, and in the "function" box write "enable_validation" when the value is "yes", and "disable_validation" when the value is "no".

Now, assuming your text box field id is "text1", please add a "Load JS" action to your form, and add this code:

function enable_validation(){
$("#text1").data("gvalidate_rules", ["required"]);
function disable_validation(){

If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!