I try to use the jQuery Validation plugin to create a multi-stage tabbed form, but I keep getting the "element is undefined" error when I try to iterate over all the inputs. Any suggestions? I donβt understand what happened. I tried to check the box in several places, and this seems to be happening all over the place (i.e. Not only in the second last tab).
var tabs = $("#tabs").tabs({ disabled: [1,2,3,4,5], select: function(event, ui) { var valid = true; var current = $(this).tabs("option", "selected"); var panelId = $("#tabs ul a").eq(current).attr("href"); $(panelId).find("input").each(function(index, element) { if (!validator.element(this) && valid) { if(ui.index > current) { valid = false; } else { //re-disable the next tab } } }); return valid; } }); $(".nexttab").click(function() { var selected = $("#tabs").tabs("option", "selected"); $("#tabs").tabs("enable", selected+1); $("#tabs").tabs("option", "selected", selected + 1); });
HTML part:
<div id="general"> </div> <div id="problemtab"> <p> <input type="checkbox" name"response" id="response" value="agree" class="required"><label for="response">I Agree</label> </p> <p> <a class="prevtab navbutton"><span>Prev</span></a> <a class="nexttab navbutton"><span>Next</span></a> </p </div> <div id="lasttab"> </div>
Thanks for any help!
Edit: It giving me an error in jquery-validate.js:787 staticRules: function(element) { var rules = {}; var validator = $.data(element.form, 'validator');
Edit # 2: element / this is defined as [HTMLInputElement object]
Here is my validator:
var validator = $("#myForm").validate({ ignore : ['#tabs .inactive input'], // tells the validator to only validate elements on your current tab errorElement: "div", wrapper: "div", // a wrapper around the error message errorPlacement: function(error, element) { if (element.parent().hasClass('group')){ element = element.parent(); } offset = element.position(); error.insertBefore(element) error.addClass('message'); // add a class to the wrapper error.css('position', 'absolute'); error.css('left', offset.left + element.outerWidth()); error.css('top', offset.top); } });