First of all, for this plugin, you must have name
attributes. The jQuery Validation plugin requires unique name
attributes to keep track of all inputs.
<input id="minAge[0]" name="minAge[0]"...
<input id="maxAge[0]" name="maxAge[0]"...
<input id="minAge[1]" name="minAge[1]"...
<input id="maxAge[1]" name="maxAge[1]"...
<input id="minAge[2]" name="minAge[2]"...
<input id="maxAge[2]" name="maxAge[2]"... etc
Then within whatever function you use to dynamically add fields, you would use the .rules('add')
method.
$('#minAge[1]').rules('add', {
required: true,
lessThan: '#maxAge[1]',
// another rule, etc.
});
Since I cannot see the function that creates your new element, I can only assume you have some kind of index variable.
var min = '#minAge[' + i + ']',
max = '#maxAge[' + i + ']';
$(min).rules('add', {
required: true,
lessThan: max,
// another rule, etc.
});