jQuery validation: how to output error message to jQuery UI modal dialog
How can I change the error message of jQuery validation so when it validates the error is composed as bullet points inside a jQuery Ui modal dialog.
Tried this but it doesn't work as expected (i.e. the modal dialog only apperas once, but after it is closed, I can't bring the modal dialog back when submitting invalid data for second time).
Any tips will be appreciated. Thank you.
...
$("#myform").validate({
debug: true,
errorPlacement: function(error, element) {
error.prependTo('#dialog-message');
},
errorLabelContainer: $("dialog-message ul"),
onblur: false,
onkeyup: false,
onsubmit: true,
wrapper: "li",
showErrors: function() {
//$("#dialog").dialog("destroy");
$("#dialog-message").dialog(开发者_JAVA技巧{
modal: true,
buttons: {
Ok: function() {
$(this).dialog('close');
}
}
});
this.defaultShowErrors();
}
});
...
<div id="dialog-message" title="Download complete">
<p>test</p>
</div>
Change this line:
$("#dialog-message").dialog({
To this:
$("#dialog-message").dialag('destroy').dialog({
This will destroy/re-create the widget correctly, or alternatively...
Run this on document.ready:
$(function() {
$("#dialog-message").dialog({
modal: true,
autoOpen: false,
buttons: { Ok: function() {
$(this).dialog('close');
}
}
});
});
And call just this in your validation, this way you're just opening the same dialog widget again:
showErrors: function() {
$("#dialog-message").dialog('open');
this.defaultShowErrors();
}
To use an on-submit validation only, add this options to your js code:
jQuery("#myForm").validate({
...
onfocusout: false,
onkeyup: false,
onclick: false,
....
精彩评论