How to change error placement according to the details entered in field.
The errorPlacement
option cannot do anything like this. Once the error element container is placed within the layout using errorPlacement
, the plugin simply toggles this element as needed. Its location is not changed as the element is already there but hidden.
In other words, you cannot dynamically move the error element around the form using any of the provided options or methods.
However, if you want a message to appear near the button when there are errors within the form, look at the showErrors
option.
showErrors: function (errorMap, errorList) {
if (this.numberOfInvalids() > 0) {
$("#summary").html("Your form contains " + this.numberOfInvalids() + " errors, see details above.");
} else {
$("#summary").empty();
}
this.defaultShowErrors(); // <- default messages that appear within form
}
Basic usage demo: http://jsfiddle.net/v2h2a2mb/
You could tweak this function so that a message only appears under certain conditions. The built-in arguments are described below...
errorMap,
Type: Object,
Key/value pairs, where the key refers to the name of an input field, values the message to be displayed for that input.
errorList,
Type: Array,
An array for all currently validated elements. Contains objects with the following two properties:
message,
Type: String,
The message to be displayed for an input.
element,
Type: Element,
The DOMElement for this entry.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…