0

I'm using the jQuery Validate Plugin and I want to be able to hide the error messages next to my inputs and have a main error message at the bottom, I have this working kind of but the error messages are showing next to my input fields. (Obviously I would clean up the styling if i was using it).

As you can see at the bottom it is telling me there are 4 errors see details below.. I want this to stay but not the error messages and styling above?

enter image description here

$( ".form-group-rules" ).validate({ 
    rules: {
        rule_name: {
            required: true
        },
        rule_desc: {
            required: false
        },
        rule_type: {
            required: true
        },  
        vali_type: {
            required: true
        },
        tran_type: {
            required: true
        },
        vali_fields: {
            required: true
        },
        acct_sel: {
            required: true
        }               
    },   
  messages: {
    rule_name: "Please enter a rule name",
    rule_type: "Please select a rule type", 
    vali_fields: "Please select a validation field",
    tran_type: "Please select at least 1 transaction type",
    vali_type: "Please select a valiation type",
    acct_sel: "Please select at least 1 account"
  },
  showErrors: function(errorMap, errorList) {
    $(".error-container").html("Your form contains "
      + this.numberOfInvalids()
      + " errors, see details below.");
    this.defaultShowErrors();
  }    
});
Sparky
  • 98,165
  • 25
  • 199
  • 285
Kieron606
  • 613
  • 3
  • 13
  • 28

3 Answers3

1

May be use the Validator method

errorPlacement: function(error,element) {
    return true;
  }

It will not append the error to the inputs.

WhoAmI
  • 501
  • 3
  • 13
  • This is unnecessary additional code, because the OP is programmatically putting these messages in place with `this.defaultShowErrors()`. – Sparky Apr 06 '16 at 18:50
0

You can hide the error messages with CSS:

span.error {
  display: none;
}
Gofilord
  • 6,239
  • 4
  • 27
  • 43
0

Normally, showErrors will automatically suppress the default messages next to each input element.

You're creating your own issue because .defaultShowErrors() is the method for putting back the default messages.

Simply remove this.defaultShowErrors()...

showErrors: function(errorMap, errorList) {
    $(".error-container").html("Your form contains "
      + this.numberOfInvalids()
      + " errors, see details below.");
    this.defaultShowErrors();  // <- REMOVE THIS LINE
} 

DEMO: http://jsfiddle.net/jmdnxedq/

Sparky
  • 98,165
  • 25
  • 199
  • 285