I have a series of inputs on my page with the same css class. I would like to add jqueryvalidation rules to them based on an attribute that I have set on their parent object. The rules get added fine but the max value that I am setting is wrong. Here is the .js
$('.countable input').each(function() {
var input = $(this);
var parent = input.closest('.countable');
var dataMax = parseInt(parent.attr('data-max'));
input.rules("add", {
number: true,
min: 0,
max: dataMax,
messages: {
number: "Must be a number",
max: "Must be less than or equal to " + dataMax
}
});
});
The problem I have is that every input that is assigned a max value ends up getting the max value of 6, which happens to be the last input that is assigned by this each function. If I step through the each, I can see that dataMax has the correct value when it is assigned, but every input gets the same data max assigned to it. Is there another way to do this?
inputelement contain a uniquenameattribute?