ValidationRule
Description
A ValidationRule is a type that is used to identify a ValidationRuleDefinition from the DataGridOptions.validationRuleDefinitions. It can be used as a string or a ValidationRuleConfiguration.
The string, or the key from ValidationRuleConfiguration, will be the reference to find the corresponding ValidationRuleDefinition from the DataGridOptions.validationRuleDefinitions.
A ValidationRule can be provided through the ColumnDefinition.validationRules property.
Default ValidationRule exists such as range, required and length.
It is simpler to define a ValidationRule as a string, unless some options are necessary. Options are useful when redefining a default ValidationRule to set its min, max and/or errorMessage properties. Options can also be used for a custom ValidationRule when specific data needs to be passed to the ValidationRuleDefinition.validate function.
Default Possible values
|
Name |
Type |
Value |
Description |
|---|---|---|---|
|
range |
string |
“range” |
validates if the value is greater or equal to its |
|
required |
string |
“required” |
Validates if the value is null, undefined or an empty string. |
|
length |
string |
“length” |
validates if the value’s length is greater or equal to its |
Example
Used as keys to identify the id of ValidationRuleDefinition with the ColumnDefinition.validationRules property.
const columnDefinition = {
id: "currency",
validationRules: ["required", "greaterZero", "lessTen"]
};
The “greaterZero” and “lessThan” values must be found amongst the keys in the ValidationRuleDefinitions provided in the options of the DataGrid for the currency column to use the corresponding ValidationRuleDefinition.