ajaxValidation reference

Options

Option name Default value Description
validationUrl null
(which means that form url will be taken)
Validation URL that is used by the plugin to make requests.
By default value is taken from action attribute of the form.
method null
(which means that form method will be taken)
Method used by the plugin to make requests. Can be POST or GET.
By default value is taken from method attribute of the form.
mode 'change'

Possible values are:

'change'
Event handler is bound to change() event of inputs of the form.
Values of input are sent one at a time.
Validation classes are assigned to the container of the input.
Validation message is stored in the .validationSummary element, which is sibling() of the form input element.

'submit'
Event handler is bound to submit() event of the whole form.
Values of all inputs in the form are sent.
Validation classes are assigned to the form element.
Validation message is stored in the .validationSummary element, which is looked up with find() method of the form.

waitForValidation false This is useful for change mode.
If true, submit button will get disabled if any form input has errors or pending validation requests.
When all errors are corrected, submit button is active again.
filter ':input'
(Corresponds to input, textarea, select and button elements)
Defines which elements should be validated.
For example, you may have a special .validation class to validate only elements you need.
sendAttr 'class' Validated element along with its name and value will also have certain attribute sent in request.
This attribute is defined by this parameter.
badClass 'bad' Class that is assigned if validation has got errors.
goodClass 'good' Class that is assigned if validation has got no errors.
waiterClass 'waiter' Class that is assigned while the validation is performed.
resultSelector '.validationSummary' Selector of the element that will store validation messages.
For mode = 'change', this element should be a sibling() of the validated input.
For mode = 'submit', this element should be single for the whole form.

Callbacks

Name Description Parameters Return values
beforeValidate (queryform)

beforeValidate is called after validation has been triggered by the element, but before query is sent to server.

You may use this callback to make changes to query and return it. Plugin will use your new query instead.

this - element that triggered the validation (input for mode = 'change' and form for mode = 'submit')

query - query object that is to be passed to server. It's structure is:

{
	Element name : {
		name : Element name,
		value : Value of the element,
		attr : Element's attribute defined in options
	},
	Another element name : {
		... 
	}
}
			

form - form element (same to this for mode = 'submit').

Optional:

false to prevent default behaviour.

string to pass to server.

afterValidate (hasErrormessage)

afterValidate is called after element has been validated.

You may use this callback to .

this - element that triggered the validation (input for mode = 'change' and form for mode = 'submit')

hasError - boolean that shown whether element has passed validation or not.

message - response received from the server.

Optional:

false to prevent default behaviour.

string to be used instead of server's response.

onError (message)

This is similar to afterValidate, but this callback is triggered only if validation has errors.

this - element that triggered the validation (input for mode = 'change' and form for mode = 'submit')

message - response received from the server.

Optional:

false to prevent default behaviour.

string to be used instead of server's response.

Methods

Methods are called this way:

$('form').ajaxValidation(method_name, [parameters, ... ]);

Name Description Parameters Return values
validate (filter)

Provides a manual way to trigger validation.

Optional:

filter - selector to filter elements that are to be validated. Skip to validate all elements.
Anyway elements should match filter option in the settings.

destroy()

Destroys plugin instance, all its internal data and event handlers.

prepareQuery (filter[scope][sendAttr])

This will create query object (as described in beforeValidate callback).

filter - selector that determines which elements should be put in the query object.

Optional:

scope - container that holds elements defined in filter parameter.
Will be used this way: $(filter, scope)

sendAttr - attribute of the elements to be put in the query object along with element's name and value.
If not set, the sendAttr option from settings will be used.

object - query object (see beforeValidate callback)