admin管理员组文章数量:1297131
I am using the JQuery Validation plugin for client side form validation. In addition to the colorful styling on invalid form fields, my client requires that a popup message be shown. I only want to show this message when the submit button is click because it would drive the user crazy otherwise. I tried the following code, but errorList is always empty. Anyone know the correct way to do something similar.
function popupFormErrors(formId) {
var validator = $(formId).validate();
var message = '';
for (var i = 0; i < validator.errorList.length - 1; i++) {
message += validator.errorList[i].message + '\n';
}
if (message.length > 0) {
alert(message);
}
}
$('#btn-form-submit').click(function(){
$('#form-register').submit();
popupFormErrors('#btn-form-submit');
return false;
});
$('#form-register').validate({
errorPlacement: function(error, element) {/* no room on page */},
highlight: function(element) { $(element).addClass('invalid-input'); },
unhighlight: function(element) { $(element).removeClass('invalid-input'); },
...
});
Update From the info in the accepted answer I came up with this.
var submitClicked = false;
$('#btn-form-submit').click(function() {
submitClicked = true;
$('#form-register').submit();
return false;
});
$('#form-register').validate({
errorPlacement: function(error, element) {/* no room on page */},
highlight: function(element) { $(element).addClass('invalid-input'); },
unhighlight: function(element) { $(element).removeClass('invalid-input'); },
showErrors: function(errorsObj) {
this.defaultShowErrors();
if (submitClicked) {
submitClicked = false;
... create popup from errorsObj...
}
}
...
});
I am using the JQuery Validation plugin for client side form validation. In addition to the colorful styling on invalid form fields, my client requires that a popup message be shown. I only want to show this message when the submit button is click because it would drive the user crazy otherwise. I tried the following code, but errorList is always empty. Anyone know the correct way to do something similar.
function popupFormErrors(formId) {
var validator = $(formId).validate();
var message = '';
for (var i = 0; i < validator.errorList.length - 1; i++) {
message += validator.errorList[i].message + '\n';
}
if (message.length > 0) {
alert(message);
}
}
$('#btn-form-submit').click(function(){
$('#form-register').submit();
popupFormErrors('#btn-form-submit');
return false;
});
$('#form-register').validate({
errorPlacement: function(error, element) {/* no room on page */},
highlight: function(element) { $(element).addClass('invalid-input'); },
unhighlight: function(element) { $(element).removeClass('invalid-input'); },
...
});
Update From the info in the accepted answer I came up with this.
var submitClicked = false;
$('#btn-form-submit').click(function() {
submitClicked = true;
$('#form-register').submit();
return false;
});
$('#form-register').validate({
errorPlacement: function(error, element) {/* no room on page */},
highlight: function(element) { $(element).addClass('invalid-input'); },
unhighlight: function(element) { $(element).removeClass('invalid-input'); },
showErrors: function(errorsObj) {
this.defaultShowErrors();
if (submitClicked) {
submitClicked = false;
... create popup from errorsObj...
}
}
...
});
Share
edited Jun 17, 2010 at 19:40
Lawrence Barsanti
asked Jun 17, 2010 at 16:25
Lawrence BarsantiLawrence Barsanti
33.4k10 gold badges49 silver badges68 bronze badges
1 Answer
Reset to default 4You should really look at using the following option for jQuery Validation
showErrors
here is a link to the documentation http://docs.jquery./Plugins/Validation/validate#options
本文标签:
版权声明:本文标题:javascript - How to use JQuery Validate to create a popup with all form error when the submit button is clicked? - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741646715a2390226.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论