简体   繁体   English

如何使用jQuery验证插件忽略输入字段的“远程”验证

[英]How to ignore “remote” validation for an input field using jQuery validation plugin

I am trying to ignore a "remote" validation property for a form using jQuery validation plugin, so I can enable it when the form is submitted instead of an onBlur of a field. 我正在尝试使用jQuery验证插件忽略表单的“远程”验证属性,因此我可以在提交表单而不是字段的onBlur时启用它。 I have the following code, but am getting a syntax error. 我有以下代码,但出现语法错误。 How can I fix it? 我该如何解决?

$(document).ready(function() 
{ 
        $("#checkNameForm").validate( {
        "onkeyup":false,
        "rules":{
            "Name":{
                "required":true,
                "minlength":5,
                "maxlength":10,
                "remote":"\/abc\/def\/checkname"
            }
        },
        "messages":{
            "Name":{
                "required":"Please enter a Name.",
                "remote":"Name is already in use."
            }
        },
        "ignore":"input[
            remote
        ]   ",
        success:function(label) {
             label.addClass("success"); 
        },
        "validClass":"success"
    } ); 
});

Having line breaks inside of the ignore option is the issue: 问题是:在ignore选项内有换行符:

jsFiddle 的jsfiddle

$(document).ready(function() 
{ 
        $("#checkNameForm").validate( {
        onkeyup: false,
        rules: {
            "Name": {
                "required":true,
                "minlength":5,
                "maxlength":10,
                "remote":"\/abc\/def\/checkname"
            }
        },
        messages: {
            "Name": {
                "required":"Please enter a Name.",
                "remote":"Name is already in use."
            }
        },
        ignore: "input[remote]",
        success: function(label) {
            label.addClass("success"); 
        },
        "validClass":"success"
    } ); 
});

您可以使用这种更简单的方法从元素中删除远程验证: $('#myfield').rules('remove', 'remote');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM