-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Hello, I'm trying unsuccessfully to add two custom rules for two dynamically generated fields as such:
<input type="text" name="volume1" id="volume1" class="volume_fields">
<input type="text" name="volume2" id="volume2" class="volume_fields">
<input type="text" name="lesson1" id="lesson1" class="lesson_fields">
<input type="text" name="lesson2" id="lesson2" class="lesson_fields">
I need all the "class=volume_fields" to validate against some rules and "class=lesson_fields" to validate against other rules (I've simplified it to just "required" for this example). I can "add" one rule but when I try to add two I get an error. Either one works on its own but two do not. Also, interestingly, I doesn't throw an error if I don't use the "each" function, but it doesn't validate.
$('.volume_fields').each(function() {
$(this).rules("add", {
required: true,
messages: {
required: "Volume required",
}
});
});
$('.lesson_fields').each(function() {
$(this).rules("add", {
required: true,
messages: {
required: "Lesson required",
}
});
});