How to display jQuery Validation error container only on submit

后端 未结 6 836
南笙
南笙 2021-02-07 10:14

I am trying to make the Validation plugin work. It works fine for individual fields, but when I try to include the demo code for the error container that contains all of the err

6条回答
  •  日久生厌
    2021-02-07 10:55

    I have a slightly different solution:

    jQuery(document).ready(function() {
      var submitted = false;
      var validator = jQuery("#emailForm").validate({ 
          showErrors: function(errorMap, errorList) {
              if (submitted) {
                  var summary = "";
                  jQuery.each(errorList, function() {
                  summary += "
  • "; }); jQuery("#errorMessageHeader").show(); jQuery("#errorMessageHeader").children().after().html(summary); submitted = false; } this.defaultShowErrors(); }, invalidHandler: function(form, validator) { submitted = true; }, onfocusout: function(element) { this.element(element); }, errorClass: "formError", rules: { //some validation rules }, messages: { //error messages to be displayed } }); });

提交回复
热议问题