Skip to content

Can't add multiple rules() for multiple dynamic fields #2179

@dviantsoul

Description

@dviantsoul

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",
         }
    });	
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions