Forums

Disable/enable validation events not working with dropdown changed through Ajax

bmurphey 22 Feb, 2016
I am using Ajax to dynamically load options into a dropdown. Another field's validation needs to be disabled/enabled depending upon which option is loaded into the dropdown. I tried using the 'Enable Validation' and 'Disable Validation' Events under the Designer tab, but with no success. For a test, I tried the 'Enable Validation' and 'Disable Validation' events using a checkbox (that I manually check) as the trigger, and they successfully changed the validation. So, I assume that the Designer tab Events won't work with an element changed through Ajax?

Any suggestion on how to go about enabling and disabling validation after an Ajax?

Thanks -

-Brian
GreyHead 22 Feb, 2016
Hi Brian,

As far as I know the Validation and the Events scripts all run when the page loads so you can't easily add/remove validation after that :-(

If you can disable the input then the validation will ignore the input. It if has to stay enabled and be validated then there is a problem.

I can think of two solutions - one would be to have two inputs in the form which are the same except for the id with one validated and one not. Then use JavaScript on the Ajax Return to enable/disable the appropriate copy.

The second approach would be to use the jQuery validation library instead of the CF built-in validation. That is more flexible and has more hooks/events that let you change validation on the fly.

Bob
bmurphey 22 Feb, 2016
Thanks for the reply. The first idea sounds more simple, so I will give it a try first.

Many thanks!

-Brian
This topic is locked and no more replies can be posted.