Reputation: 15032
I use jquery validation plugin in hand with form plugin for jQuery.
I turned on validation of email format, it is ok that it started to validate emails on the run and tells user immediately that he/she typed invalid email format.
However it is not OK that this check also fires up the error message box - is there a way to force validation() to show error labels next to inputs but at the same time to not to fire/show error_box? (in result) . I want to add anything to the result box AFTER user clicks the submit button - is it possible ?
EDIT: I thought it was clear, clearly it is not so I am adding the piece of code :)
EDIT 3: Where I am heading to: I DO want the messages in the target: .result but ONLY after clicking submit button - NOT anytime sooner it should be more clear now :)
var zadost = $("#validate_zadost").validate({
focusInvalid: false,
submitHandler: function(form) {
$(form).ajaxSubmit({
target: ".result",
success: function(){ zadost.resetForm(); }
});
},
showErrors: function(errorMap, errorList) {
$(".result")
.html("<div class='error_box'><h1>Nebyly vyplňeny povinné údaje nebo byly vyplňeny špatně!</h1><p>Žádost nebyla odeslána - prosím doplňte povinné údaje (ve správném formátu). (červeně zvýrazněny)</p></div>");
this.defaultShowErrors();
},
errorPlacement: function(error, element) { //error message and JQUERY element coming...
if( element.is(':checkbox') ) error.insertBefore(element).addClass('zadostErrorCheckbox');
else error.insertAfter(element);
}
});
Upvotes: 1
Views: 1050
Reputation: 98738
Quote Title:
"how to turn off non-submit validation results?"
Sounds like you want to turn off all the "events"...
$('#myform').validate({
// options & rules,
onkeyup: false, // prevent validation on every key up
onfocusout: false, // prevent validation after leaving field
onclick: false // prevent validation when clicking radio and checkbox
});
Do not use the onsubmit
option since it's already the default behavior (setting it to true
will break the plugin).
Quote OP:
"However it is not OK that this check also fires up the error message box - is there a way to force
validate()
to show error labels next to inputs but at the same time to not to fire/showerror_box
? (in result). I want to add anything to the result box AFTER user clicks the submit button - is it possible?"
I can't see your code so I don't know what you've done, however, showing only error message labels next to the input fields is already the default behavior. Something in your code must be causing the other things to happen here.
edit: remove your entire showErrors
callback function if you don't want to show the error box and only show errors in labels next to input elements.
Upvotes: 2