Tuesday, 15 February 2011

ajax - Open modal when jQuery validation remote fails -



ajax - Open modal when jQuery validation remote fails -

i'm using jquery validation plugin, , works great.

i want able both display message , trigger modal (alert() in example) whenever remote ajax fails. can't figure out how both. now, triggers alert() expected, appends error message "please prepare field", should own custom error message.

here's 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 required", tlf: { required: "field tlf required!", remote: function () { // want add together message aswell, not alert alert("failed - tlf taken!"); } } }, submithandler: function(form) { dosomethinggreatonsuccess(); }, errorplacement: function (error, element) { error.appendto(element.parent()); } });

quote op comment: "the returned string works everytime, .reveal() fires first time, after page loaded."

i think you're getting modal 1 time because validate plugin constructs message 1 time (then uses hide/show). if want fired off every time, seek highlight callback function instead. utilize in conjunction onkeyup , onfocusout set false.

onkeyup: false, onfocusout: false, highlight: function(element, errorclass) { if ($(element).attr('name') === 'remotefieldname') { $('#mymodal').reveal(); } }

demo: http://jsfiddle.net/nfrvt/1/

jquery ajax jquery-validate

No comments:

Post a Comment