Jquery Validate Uncaught Typeerror Cannot Read Property 'form' Of Undefined
I am using jquery validate http://jqueryvalidation.org/ I have a form with a first field added manually (hard coded) Then adding more fields is done programatically. The ARE append
Solution 1:
You are adding rule taking ID string.Instead take the element selector, and add rule to that selector.
var $largestID = $("#to-append > div:last > div:first > input:first").attr("id");
console.log($largestID); //throws right id
$('#'+$largestID).each(function () {
$(this).rules('add', {
requzired: true,
minlength: 3,
pattern: yt
});
});
Use the $('#'+$largestID) to get the field of that ID, and then add rules.
To add rules to array, use
$('#'+$largestID) .each(function () { }
you can even validate the array of names of that element,
$('#'+$largestID).validate({
rules: {
'url[]': {
required: true,
}
}
});
Solution 2:
There's no need to use the ID. You have a selector that returns the element, add the rule to that directly.
$("#to-append > div:last > div:first > input:first").rules("add", {
required: true,
minlength: 3,
pattern: yt
});
Post a Comment for "Jquery Validate Uncaught Typeerror Cannot Read Property 'form' Of Undefined"