Jake Jake - 4 months ago 28
Javascript Question

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

Answer

Having line breaks inside of the ignore option is the issue:

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