By default, the label element is used to display the verification prompt information, and css class is added. Through css, you can easily set the error control and display mode of error information.
/* Input control verification error */
Form input. error {border: solid 1px red ;}
/* Verification error message */
Form label. error {width: 200px; margin-left: 10px; color: Red ;}
To customize the display mode, you can modify the default display mode of jquery. validate.
The label is used by default to Display error messages, which can be modified through the errorElement attribute.
ErrorElement: html tag of the error message
$ (". Selector"). validate
ErrorElement: "em"
})
You can use other elements to wrap a layer in the error message.
Wrapper: the html Tag is encapsulated in the outer layer of the error message.
$ (". Selector"). validate ({
Wrapper: "li"
})
The default css class for verification errors is error, which can be modified through errorClass.
ErrorClass: the css class used for error Verification
$ (". Selector"). validate ({
ErrorClass: "invalid"
})
Also customize the action when the verification is successful
Success: If the value is a string, it is treated as a css class. If it is a function, it is executed.
$ (". Selector"). validate ({
Success: "valid"
})
Or
Success: function (label ){
Label.html (""). addClass ("checked ");
}
You can also unify the error messages to a container for display.
ErrorLabelContainer: Unified error messages to a container for display.
$ ("# Myform"). validate ({
ErrorLabelContainer: "# messageBox"
})
By default, error messages are placed after verification elements. You can customize the display location of error messages.
$ (". Selector"). validate ({
ErrorPlacement: function (error, element ){
Error. appendTo (element. parent ("td"). next ("td "));
}
})
Further, you can define a group to unify the error information in several places and use the error Placement to control where the error information is stored.
Groups: defines a group.
$ (". Selector"). validate ({
Groups :{
Username: "fname lname"
},
ErrorPlacement: function (error, element ){
If (element. attr ("name") = "fname" | element. attr ("name") = "lname ")
Error. insertAfter ("# lastname ");
Else
Error. insertAfter (element );
}
})
Highlight
Highlight: highlighted. By default, errorClass is added.
Unhighlight: corresponds to highlight and is highlighted in reverse mode.
$ (". Selector"). validate ({
Highlight: function (element, errorClass ){
$ (Element). addClass (errorClass );
$ (Element. form). find ("label [for =" + element. id + "]"). addClass (errorClass );
},
Unhighlight: function (element, errorClass ){
$ (Element). removeClass (errorClass );
$ (Element. form). find ("label [for =" + element. id + "]"). removeClass (errorClass );
}
});
Or you can customize the error display.
ShowErrors: The display handle is incorrect.
$ (". Selector"). validate ({
ShowErrors: function (errorMap, errorList ){
$ ("# Summary" pai.html ("Your form contains" + this. numberOfInvalids ()
+ "Errors, see details below .");
This. defaultShowErrors ();
}
})