adding jquery validation dynamically

后端 未结 3 1514
终归单人心
终归单人心 2020-12-16 07:47

I found where you can add jquery validation rules dynamically like this:

$(\"#ParentAdNumber\").rules(\"add\", { required: true });

But how

相关标签:
3条回答
  • 2020-12-16 08:18
    $("#ParentAdNumber").rules("remove", "required");
    

    From the documentation: http://docs.jquery.com/Plugins/Validation/rules

    Edit: messages

    Adding:

    $("#ParentAdNumber").rules("add", {
        optionName: true,
        messages: {
            optionName: "message for optionName"
        }
    });
    

    Removing:

    $("#ParentAdNumber").rules("remove", "messages");
    

    Looking at the source code of Validation, it doesn't look like you can remove specific messages...

    0 讨论(0)
  • 2020-12-16 08:18

    Simple!

    $("#ParentAdNumber").rules("add", {
        required: true,
        messages: {
            required: "Required input"
        }
    });
    

    you can change the message storing the rule:

    var objRule = $("#ParentAdNumber").rules();
    

    Changing:

    objRule.messages.required = "New message";
    

    and Re-applying:

    $("#ParentAdNumber").rules("add", objRule);
    
    0 讨论(0)
  • 2020-12-16 08:37

    This should do it....

    .rules("add", {required: true, messages: {required: "Required input")}
    
    0 讨论(0)
提交回复
热议问题