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, { ruleName: true, messages: { ruleName: 'Error message' } }, errorMessageSelector, validationContext)
inputSelector
: the jQuery selector for the input field.validationRules
: the validation rules dictionary, consisting of a validation method as key and it's configuration as value. A key of messages, optional, can be specified as a dictionary of validate method name to error message (to override default error messages).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.
Supported validation rules
date
: The input contains a valid date. Configuration value should always betrue
dateISO
: The input contains a valid ISO date. Configuration value should always betrue
digits
: The input contains only numeric digits. Configuration value should always betrue
email
: The input contains a valid email address. Configuration value should always betrue
emailexists
: The input contains an email address not used by a currently registered member in the community. Configuration value should always betrue
emails
: The input contains one or more valid email addresses separated by commas or semi-colons. Configuration value should always betrue
equalTo
: The input's value is equal to the value of another input. The configuration value is a string jQuery selector representing the input to validate against.groupnameexists
: The input contains a group name that does not currently exist within the provided parent group in the community. Configuration value should be an object with a function namedgetParentId()
that returns the integer ID of the parent group in which to search for names.mailinglistnameexists
: The input contains a mailing list name that is not currently in use within the community. Configuration value should be an object with a propertyid
with the integer value of the existing mailing list being edited ortrue
max
: The input represents a number that is at most the configured maximum value. Configuration value is the numeric maximum allowed.maxlength
: The input must be shorter (or fewer selections of a select or checkbox group must be made) than the configured maximum. Configuration value is the numeric maximum allowed.min
: The input represents a number that is at least the configured minimum value. Configuration value is the numeric minimum required.minlength
: The input must be longer (or more selections of a select or checkbox group must be made) than the configured minimum. Configuration value is the numeric minimum required.number
: The input represents a valid decimal number. Configuration value should always betrue
passwordvalid
: The input contains a value that meets the password requirements of the community. Configuration value should always betrue
pattern
: The input contains a value that matches the provided regular expression. Configuration value is the string representation of the regular expression to validate against.range
: A numeric input must be between a given numeric range, represented as an array of[minimum, maximum]
rangelength
: The input's string length must be between a given numeric length range, represented as an array of[minimum, maximum]
required
: The input must contain a value. The configuration value should always betrue
step
: The input contains a number that is a multiple of the provided configuration value. The configuration value is the number that the input must be a multiple of.url
: The input contains a valid URL. The configuration value is alwaystrue
username
: The input contains a value that matches the required username requirements set by the community. The configuration value should always betrue
usernameexists
: The input contains a value that does not exist as a username in the community. The configuration value should always betrue
wikipageexists
: The input contains a value that does not exist as the name of a wiki page within the provided context. The configuration value should be an object with a propertywikiId
set to the contextual wiki's integer ID,pageId
set to the contextual wiki page's integer ID, and a functionparentPageId()
that returns the contextual parent wiki page's integer ID.
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')