私はjQuery検証プラグインを使用していますが、それはうまく機能します。
リモートajaxが失敗したときはいつでも、メッセージを表示し、モーダル(例ではalert())をトリガーできるようにしたいと思います。私は両方を行う方法を理解することはできません。これで、alert()が期待どおりにトリガーされますが、「このフィールドを修正してください」というエラーメッセージも追加されます。これは、私自身のカスタムエラーメッセージである必要があります。
これが私が持っているものです:
$("#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());
}
});