I'm using the jQuery validation plugin, and it works great.
I want to be able to both display a message and trigger a modal (alert() in the example) whenever the remote ajax fails. I can't figure out how to do both. Now, it triggers the alert() as expected, but also appends the error message "Please fix this field", which should be my own custom error message.
Here's what I've got:
$("#adresse-form").validate({
errorElement: "span",
rules: {
navn: {
required: true,
minlength: 5,
maxlength: 25
},
tlf: {
required: true,
digits: true,
minlength: 8,
remote: {
url: "/ajax/check_tlf",
type: "post"
}
}
},
messages: {
navn: "Field Name is required",
tlf: {
required: "Field tlf is required!",
remote: function () { // i want to add the message aswell, not just the alert
alert("failed - tlf is already taken!");
}
}
},
submitHandler: function(form) {
doSomethingGreatOnSuccess();
},
errorPlacement: function (error, element) {
error.appendTo(element.parent());
}
});