Forums

Adding validation dynamically

dotjoomla 07 Jun, 2014
Hi,
I am having a problem, I need you input/help.
I am creating a form, the form have several sections which hide and show on selecting an option from a dropdown.
So I have created several divs for each section and by default they are all hidden. Now on selecting the option from dropdwon, I show the respective div.

Now this each div ( section) has 2 fields that need to be validated as required. I can't add validation class ( class = "validate['required']" ) by default, so I am adding them dynamically using jquery to fields inside the selected section. But this validation don't work. but i add by default they work.
So there is something that also need o be added beforehand. Can you please help me in this.

For an example
drop down options are = P1, P2, P3, P4
Now we select P1 and the P1 div is shown, now it has 1 field textarea ( description ). I want to validate that as required. But If the user selects p2 than the above textarea won't be validated but the another textarea will be validated.

Thanks in Advance.
GreyHead 07 Jun, 2014
Hi dotjoomla,

In ChronoForms v4 set the validation as you would for a normal input. Then disable the input when you hide it and re-enable it when you show it again. Then the validation will work OK.

I also clear any inputs that are being hidden.

Bob
dotjoomla 07 Jun, 2014
Wow, Thanks a ton for quick reply.
I will soon give it a try.
dotjoomla 10 Jun, 2014
Just came to thank you people again !!
@Bob, I am really thankful for your help, Keep up the good job !!
This topic is locked and no more replies can be posted.