ahmed_sadman — 2012-08-29T08:25:14-04:00 — #1
JQuery Validate plugin is a good thing to control web-forms. I have learnt about it, but I want to make something extra.
Suppose, I have a <select> tag with a few options. If a user selects a specific one, another input field gets added and it's required on that circumstance.
But, I want to do, that field will only be required if the specific option is selected.
<select id="any" name="any">
<options>2</options> <!-- make it specific -->
<label for="any" id="any">Type</label>
<input type="text" id="any" name="any">
If the user selects '2' in selection, the hidden field is shown and it's required. Otherwise, if the user didn't select '2', the field will not be shown and it's not required. How to accomplish such condition?
I have read the JQUERY Validate Doc, but it's not so friendly for newbies. So I think you can explain me a lot.
Thanks in advance....
paul_wilkins — 2012-08-29T18:46:20-04:00 — #2
When the form requirements change, you would need to remove the older validation rules and create a new set of validation rules that apply to the new form setup.
ahmed_sadman — 2012-09-01T08:05:56-04:00 — #3
Ok. But how? I am new and can't understand. Again, my whole form requirements doesn't change, it only applies to one field.
paul_wilkins — 2012-09-01T08:55:34-04:00 — #4
It should be possible then to add and/or remove certain rules for the validation then. Let's see if that is possible with the validation plugin.
And yes, it does indeed seem that there are methods to add and remove rules. If you go to the [plugin methods section you will see them there. The [url="http://docs.jquery.com/Plugins/Validation/rules#rules.28.C2.A0.22add.22.2C.C2.A0rules_.29"]add rules and [url="rules.28.C2.A0.22remove.22.2C.C2.A0.5Brules.5D_.29"]remove rules](http://docs.jquery.com/Plugins/Validation#Plugin_methods) methods.
ahmed_sadman — 2012-09-04T06:07:46-04:00 — #5
Many many thanks. I didn't read that thing. But now it's clear