Forums

Dynamic Validation?

bobmitch 14 May, 2012
Hi,

Using CF4 and J2.5 - I have created a form which has dynamically visible fields easily enough - how can I toggle or change the validation required for these fields?

Simple adding or removing the validation class ( e.g. validation['required','alpha'] ) doesn't work, which leads me to believe that the validation engine analyzes the form once, not every submission.

e.g.

http://perryballard.com/lakeshoreelectric/rfq

When 'other' is chosen for 'installed manufacturer' - new fields are shown. I would like these to be validated only when visible. How can this be achieved?

Thanks in advance!
GreyHead 15 May, 2012
Hi bobmitch,

The FormCheck library used in CFv4 ignores disabled inputs so the trick is to disable the hidden inputs and enable them when they are displayed. I'd suggest you also clear them when they are hidden to stop any stray values popping up later.

There's an example here

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