This module handles form control validation and was written with the intention of being mixed into the BaseFormControl module. It provides the ability handle more complex validation, including asynchronous validation. This means that it is possible for a form to request remote data (e.g. to check whether or not a suggested identifier has already been used).
The validators that are currently provided include checking that the length of a form field value is neither too long or too short, that it matches a specific Regular Expression pattern and whether or not the value is unique. Each validator should be configured with an explicit error message (if no error message is provided then the invalid indicator will be displayed with no message).
Multiple validators can be chained together and if more than one validator reports that they are in error then their respective error messages will be displayed in sequence.
- Copyright:
- Copyright (C) 2005-2020 Alfresco Software Limited
- License:
- GNU Lesser General Public License, see: Open Source Licensing
- Source:
Example
validationConfig: [
{
validation: "minLength",
length: 3,
errorMessage: "Too short"
},
{
validation: "maxLength",
length: 5,
errorMessage: "Too long"
},
{
validation: "numericalRange",
min: 500,
max: 10000,
errorMessage: "Must be between 500 and 10000"
},
{
validation: "regex",
regex: "^[0-9]+$",
errorMessage: "Numbers only"
},
{
validation: "validateUnique",
errorMessage: "Already used",
itemsProperty: "items",
publishTopic: "GET_VALUES"
},
{
validation: "validationTopic",
validationTopic: "ALF_VALIDATE_WHITESPACE_TOPIC",
errorMessage: "No initial or trailing whitespace"
}
]
Extends
Members
-
_validateMatchSubscriptionHandle :object
-
Holds the subscription for publication of changes in value of the target form control configured for the validateMatch validator.
Type:
- object
- Default Value:
- null
- Source:
-
_validateMatchTargetValue :object
-
Used to keep track of changes to the value of the target form control configured for the validateMatch validator.
Type:
- object
-
_validateUniqueConfig :object
-
Stores the validator configuration for validating uniqueness so that it doesn't need to be included in the payload from the called service. It is set in validateUnique and reset to null in onValidationUniqueResponse.
Type:
- object
- Default Value:
- null
- Source:
-
_validationErrorMessage :string
-
This is used to build up the overall validation message.
Type:
- string
- Default Value:
- null
- Source:
-
_validationInProgress :boolean
-
Indicates whether or not validation is currently in-progress or not
Type:
- boolean
- Default Value:
- false
- Source:
-
_validationInProgressState :boolean
-
Keeps track of the current validation state. Is updated by each call back to validationComplete
Type:
- boolean
- Default Value:
- true
- Source:
-
_validationInProgressTimeout :object
-
A timeout for showing in-progress validation indicators. Used to debounce the display of the indicator to prevent "jumping".
Type:
- object
- Since:
- 1.0.89
- Source:
-
_validationWarningMessage :string
-
This is used to build up the overall validation message for warnings.
Type:
- string
- Since:
- 1.0.91
- Default Value:
- null
- Source:
-
_validatorsInProgress :object
-
Keeps track of all the validators that are currently processing. This array is added to by processValidationArrayElement and removed from during validationComplete
Type:
- object
- Default Value:
- null
- Source:
-
i18nRequirements :Array
-
An array of the i18n files to use with this widget.
Type:
- Array
-
validationProgressDisplayTimeout :number
-
The time in milliseconds to wait before displaying the validation progress indicator.
Type:
- number
- Since:
- 1.0.89
- Default Value:
- 1000
- Source:
Methods
-
_validateMatchTargetValueChanged(validationConfig, payload)
-
When the match target value changes, update a local copy to compare against.
Parameters:
Name Type Description validationConfig
object The configuration for this validator payload
object A payload containing the latest match target value -
countValidatorsInProgress() → {number}
-
Counts the validators that are currently in progress.
Returns:
The number of validators still in progress- Type
- number
-
maxLength(validationConfig)
-
This validator checks that the current form field value is longer than the configured value.
Parameters:
Name Type Description validationConfig
object The configuration for this validator -
minLength(validationConfig)
-
This validator checks that the current form field value is shorter than the configured value.
Parameters:
Name Type Description validationConfig
object The configuration for this validator -
numericalRange(validationConfig)
-
This validator ensures that the form value is a number that falls within a range. It is acceptable to only provide the min or max of the range.
Parameters:
Name Type Description validationConfig
object The configuration for this validator -
onValidationTopicFailure(payload)
-
Handles failed requests to peform validation by publishing a topic. Assumes valid data on failure.
Parameters:
Name Type Description payload
object The details of the validation failure - Since:
- 1.0.89
- Source:
-
onValidationTopicResponse(payload)
-
The response called by the topic specified in validationTopic. Receives the isValid state and updates the form.
Parameters:
Name Type Description payload
object -
onValidationUniqueResponse(payload)
-
This is the callback function that is called as a result of using the validateUnique validator.
Parameters:
Name Type Description payload
object The payload containing the items to iterate through looking for an existing use of the form field value -
processValidationArrayElement(validationErrors, validationConfig, index) → {boolean}
-
This function is called from the processValidationRules function for each element of the validationConfig configuration attribute. It checks that the supplied 'validation' attribute maps to a function a function (the core validation functions are defined in the FormControlValidationMixin module).
Parameters:
Name Type Description validationErrors
array An array to populate with validation errors. validationConfig
object The current element to process index
number The index of the element in the array Returns:
True if validation is passed and false otherwise- Type
- boolean
-
regex(validationConfig)
-
This validator checks the current form field value against the configured regex pattern.
Parameters:
Name Type Description validationConfig
object The configuration for this validator -
reportValidationResult(validationConfig, result)
-
This function should be called by all validators when they have finished validating the current entry.
Parameters:
Name Type Description validationConfig
object The configuration for the validator that has just completed result
boolean Whether or not the validation was successful or not -
startValidation()
-
Called to start processing validators. If validation is already in progress then a flag will be set to queue another validation run once the current processing has completed.
-
validateMatch(validationConfig)
-
This validator checks that the value of the form control with a "fieldId" attribute matching the configured "targetId" attribute in the validation configuration matches the current value of this form control.
Parameters:
Name Type Description validationConfig
object The configuration for this validator -
validateUnique(config)
-
This validator checks that the current form field value has not already been used on another item. It should be configured with a 'publishTopic' attribute to request a list of existing items and a 'publishPayload' attribute to go with it. Optionally an 'itemsProperty' attribute can be configured that will identify the attribute in the returned payload that will contain the array of items to iterate through looking for a value that matches the currently entered value.
Parameters:
Name Type Description config
object The configuration for this validation -
validationComplete()
-
This function is called when all validators have reported their finished state.
-
validationTopic(validationConfig)
-
Call a topic to validate the value of a form control. That topic will receive the value in payload.value & should publish a response on payload.alfResponseTopic The response payload should contain an "isValid" boolean property.
Parameters:
Name Type Description validationConfig
object