jQuery Validate - Hide display validation error messages / show custom errors

前端 未结 3 539
梦如初夏
梦如初夏 2020-12-23 19:13

I\'m using jQuery Validate, but I really don\'t want to have any error messages whatsoever. Rather, I need to have red boxes around offending inputs/selects/etc. These red b

相关标签:
3条回答
  • 2020-12-23 19:51

    This is how I do it. Just put $.validator.messages.required = ''; before your call to initialise validate() i.e.:

    $.validator.messages.required = '';
    $('#formData').validate({});`
    

    This will make it show the styles on the inputs, but no message labels!

    0 讨论(0)
  • 2020-12-23 19:52

    Use a custom error placement function (see the plugin's options) that doesn't append the error message to anything.

    $('#form').validate({
      errorPlacement: function(error,element) {
        return true;
      }
    });
    

    Or you could put the error messages elsewhere on the page - say in a DIV at the top of the page.

    0 讨论(0)
  • 2020-12-23 20:08

    You can override the showErrors function:

    jQuery('form').validate({
        showErrors: function(errorMap, errorList) {
            // Do nothing here
        },
        onfocusout: false,
        onkeyup: false,
        rules: {
            email: {
                required: true
            }
        },
        messages: {
            email: {
                required: 'The email is required'
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题