Forums

Conditional form validation on datepicker does not work

mfactory 28 Jul, 2011
Hi!,

I'm using conditional form validation as described in this topic:
http://www.chronoengine.com/forums.html?cont=posts&f=2&t=15812

got it all working, except one item: I have a date field which doesn't perform as it should.
The class required gets set and unset allright (I can check in the code), but for some reason, when the class required is set by the event handler, it does not do anything on submit. So, on submit, you are allowed to leave the field empty, totally disregarding the required class.

Leaving the event handler out and setting the required class from the start in the form does work however.

Does anyone know how to get around this?

Thanks, Nathalie
GreyHead 28 Jul, 2011
Hi Nathalie,

Please post a link to the form so I can take a quick look.

Bob
a.carter 19 Sep, 2011
Hi Bob,

I am having the exact same issue but with checkboxes. I thought I'd post it here instead of creating a new thread. Since the original poster hasn't replied, i've attach my backup file (chronoforms v3.2) so you can see it.

I have a selection of 4 radio boxes. Depending on which one you select I would like the check box for that 'Payment' Option to be required... if user selects credit card then check-box for "authorize credit" must be required. If user selects Direct Debit then the authorize debit check-box must be required and the authorize credit check-box no longer required. If you choose option 3 and 4 then neither of the 2 check-boxes are required as I do not need an customer authorization for those types of payment.

The code I have works, it changes the classes accordingly. But it doesn't validate on submit. the class is set by the conditional code but when you hit submit it still processes the form even if not ticked. If I remove all the conditional add remove class code and just set it with the validate class from the start, then the validation works on submit. Just not when the code applies the class to the item.

Any help on this would be greatly appreciated it's a huge show stopper for the current site im developing.😟
GreyHead 19 Sep, 2011
Hi a.carter,

Unfortunately you can't do it like that - changing the classes in the browser has no affect on the validation. The validations are set up in the PHP when the form loads using the classes set at that time. Any changes after that do nothing.

Usually in this case I set the script to enable or disable the Submit button and show an appropriate message. You need to use the onClick event as the Validation uses the onSubmit event; you also need to give the submit button an id that is not 'submit' as that causes problems with IE - I usually use id='submit_btn'.

Theoretically it's possible to alter the validations after the form loads but I've never worked out how to do it :-(

Bob
polderguy 01 Dec, 2011
Bob,

Theoretically it's possible to alter the validations after the form loads but I've never worked out how to do it :-(



After reading this post on stackoverflow.com I got it working:

Livevalidation remove method works great now.

PolderGuy
GreyHead 02 Dec, 2011
Hi PolderGuy,

Excellent, thank you. I need to spend more time to understand the JavaScript there but I can see why I was failing to get this to work.

Please can you post an example of the code you used with ChronoForms?

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