jQuery.fn.evolutionValidation
Supports validation related to one or more button/link click events.
Usage
Initializes validation.
$('SELECTOR').evolutionValidation(options)
Initializes validation. The selector should represent one or more links/buttons that can submit the form being validated.
Options
validateOnLoad
: True/false/null. If true, validation will be performed when the page loads. If false, it will not. If null, the form will be validated on load if any textual input fields have values.onValidated
: Function called when validation is performed. Parameters are: validationSuccessful (bool), submitButtonClicked (bool), failedValidationContext (object).onSuccessfulClick
: Function called when a submit button is clicked and validation was successful. Parameters are: event.
Methods
addField
Registers an input field for validation associated to the selected submit buttons/links given:
$('SELECTOR').evolutionValidation('addField', inputSelector, validationRules, errorMessageSelector, validationContext)
inputSelector
: the jQuery selector for the input field.validationRules
: the jQuery validation-based validation rules definition.errorMessageSelector
: the jQuery selector for the element(s) to be populated with validation information associated to this field.validationContext
: any object providing context for this field. This value is passed to the onValidated function associated to this set of submission links/buttons.
addCustomValidation
Registers a custom validation function for validation associated to the selected submit buttons/links given:
$('SELECTOR').evolutionValidation('addCustomValidation', id, validationFunction, errorMessage, errorMessageSelector, validationContext)
id
: the identifier for this validation rulevalidationFunction
: the function that, when called, returns a boolean identifying whether the test is valid or not.errorMessage
: the text to show when this custom validation fails.errorMessageSelector
: the jQuery selector for the element(s) to be populated with validation information associated to this custom rule.validationContext
: any object providing context for this rule. This value is passed to the onValidated function associated to this set of submission links/buttons.
This method returns a function reference that can be called to execute this custom validation rule. For example, the returned function could be attached to an onchange event for another jQuery plugin.
isValid
Returns whether the set of fields and custom rules are valid for the selected submit button/link set. This does not force validation to occur, but returns the current state of the form.
$('SELECTOR').evolutionValidation('isValid')
validate
Forces validation to occur on all fields and custom rules associated to the selected submit button/link set. The result of the validation is returned.
$('SELECTOR').evolutionValidation('validate')
validateField
Forces validation on the field or fields identified by the fieldSelector within the context of the selected submit button/link set. The result of the validation is returned.
$('SELECTOR').evolutionValidation('validateField', fieldSelector)
validateCustom
Forces validation on the custom validation rule referenced by the given ID within the context of the selected submit button/link set. The result of the validation is returned.
$('SELECTOR').evolutionValidation('validateCustom', id)
reset
Resets the validation state for all registered fields as if the form was completely reloaded. This is suitable for resetting the form after an AJAX submission and clearing of the form's values.
$('SELECTOR').evolutionValidation('reset')