Buy Now
Sign in

If Then style validation

milton.martinez , March 27 2014
Featured
m
milton.martinez

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

admin

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").addClass('validate["required"]');
$("#text1").data("gvalidate_rules", ["required"]);
}
function disable_validation(){
$("#text1").removeClass('validate["required"]');
}


Regards,
Max

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