Interface ValidationOptions

Index

Properties

Properties

optional public debug?: boolean

Enables debug mode. If true, the form is not submitted and certain errors are displayed on the console (will check if a window.console property exists). Try to enable when a form is just submitted instead of validation stopping the submit.

default: false

optional public errorClass?: string

Use this class to create error labels, to look for existing error labels and to add it to invalid elements.

default: "error"

optional public errorContainer?: string

Hide and show this container when validating.

optional public errorElement?: string

Use this element type to create error messages and to look for existing error messages. The default, "label", has the advantage of creating a meaningful link between error message and invalid field using the for attribute (which is always used, regardless of element type).

default: "label"

optional public errorLabelContainer?: string

Hide and show this container when validating. (eg "#messageBox")

optional public errorPlacement?: (error: JQuery, element: JQuery) => void

Customize placement of created error labels. First argument: The created error label as a jQuery object. Second argument: The invalid element as a jQuery object.

default: Places the error label after the invalid element

optional public focusCleanup?: boolean

If enabled, removes the errorClass from the invalid elements and hides all error messages whenever the element is focused. Avoid combination with focusInvalid.

default: false

optional public focusInvalid?: boolean

Focus the last active or first invalid element on submit via validator.focusInvalid(). The last active element is the one that had focus when the form was submitted, avoiding stealing its focus. If there was no element focused, the first one in the form gets it, unless this option is turned off.

default: true

optional public groups?: Object

Specify grouping of error messages. A group consists of an arbitrary group name as the key and a space separated list of element names as the value. Use errorPlacement to control where the group message is placed.

optional public highlight?: (element: HTMLElement, errorClass: string, validClass: string) => void

How to highlight invalid fields. Override to decide which fields and how to highlight.

default: Adds errorClass (see the option) to the element

optional public ignore?: string

Elements to ignore when validating, simply filtering them out. jQuery's not-method is used, therefore everything that is accepted by not() can be passed as this option. Inputs of type submit and reset are always ignored, so are disabled elements.

optional public ignoreTitle?: boolean

Set to skip reading messages from the title attribute, helps to avoid issues with Google Toolbar; default is false for compability, the message-from-title is likely to be completely removed in a future release.

default: false

optional public invalidHandler?: (event: JQueryEventObject, validator: Validator) => void

Callback for custom code when an invalid form is submitted. Called with an event object as the first argument, and the validator as the second.

optional public messages?: Object

Key/value pairs defining custom messages. Key is the name of an element, value the message to display for that element. Instead of a plain message, another map with specific messages for each rule can be used. Overrides the title attribute of an element or the default message for the method (in that order). Each message can be a String or a Callback. The callback is called in the scope of the validator, with the rule's parameters as the first argument and the element as the second, and must return a String to display as the message.

default: the default message for the method used

optional public meta?: string

optional public onclick?: any

Boolean or Function. Validate checkboxes and radio buttons on click. Set to false to disable.

Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.

optional public onfocusout?: any

Boolean or Function. Validate elements (except checkboxes/radio buttons) on blur. If nothing is entered, all rules are skipped, except when the field was already marked as invalid.

Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.

optional public onkeyup?: any

Boolean or Function. Validate elements on keyup. As long as the field is not marked as invalid, nothing happens. Otherwise, all rules are checked on each key up event. Set to false to disable.

Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.

optional public onsubmit?: boolean

Validate the form on submit. Set to false to use only other events for validation. Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.

default: true

optional public rules?: Object

A custom message display handler. Gets the map of errors as the first argument and an array of errors as the second, called in the context of the validator object. The arguments contain only those elements currently validated, which can be a single element when doing validation onblur/keyup. You can trigger (in addition to your own messages) the default behaviour by calling this.defaultShowErrors().

optional public showErrors?: (errorMap: ErrorDictionary, errorList: ErrorListItem[]) => void

A custom message display handler. Gets the map of errors as the first argument and an array of errors as the second, called in the context of the validator object. The arguments contain only those elements currently validated, which can be a single element when doing validation onblur/keyup. You can trigger (in addition to your own messages) the default behaviour by calling this.defaultShowErrors().

optional public submitHandler?: (form: HTMLFormElement) => void

Callback for handling the actual submit when the form is valid. Gets the form as the only argument. Replaces the default submit. The right place to submit a form via Ajax after it is validated.

optional public success?: any

String or Function. If specified, the error label is displayed to show a valid element. If a String is given, it is added as a class to the label. If a Function is given, it is called with the label (as a jQuery object) and the validated input (as a DOM element). The label can be used to add a text like "ok!".

optional public unhighlight?: (element: HTMLElement, errorClass: string, validClass: string) => void

Called to revert changes made by option highlight, same arguments as highlight.

default: Removes the errorClass

optional public validClass?: string

This class is added to an element after it was validated and considered valid.

default: "valid"

optional public wrapper?: string

Wrap error labels with the specified element. Useful in combination with errorLabelContainer to create a list of error messages.

default: window