Basic form using a JQuery Accordion and attempting to validate required fields. Am I missing something simple? Thanks!
javascript:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#accordion").accordion();
$("#Form1").validate({
rules: {
AccordionField: { required: true }
}
});
});
</script>
html:
<form id="Form1" action="foo.htm">
<div id="accordion">
<h3><a href="#">Section 1</a></h3>
<div><p>content</p></div>
<h3><a href="#">Section 2</a></h3>
<div><p><input id="AccordionField" class="required" /></p></div>
</div>
<p><button type="submit">Submit</button></p>
</form>
Problem: If the second section is collapsed during the submit, validation does not validate the required field.
jQuery validate (1.9) ignores hidden fields by default. You can override this behavior using the ignore
option:
$(document).ready(function() {
$("#accordion").accordion();
$("#Form1").validate({
rules: {
AccordionField: {
required: true
}
},
ignore: []
});
});
Example: http://jsfiddle.net/andrewwhitaker/VWWkP/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With