ValidationRuleDefinition / PartialValidationRuleDefinition

Description

A ValidationRuleDefinition is an interface that exposes the necessary to define a validation function and set its options.

Properties

Property

Type

Description

options?

ValidationRuleOptionsCollection

An object representing the options of this ValidationRuleDefinition.

Methods

Method

Parameter

Type

Description

validate?

 

 

Method called to validate an editedItem.

 

validationContext

ValidationContext

The ValidationContext to validate.

 

[output]

ValidationResult

The result of the validation (either a SuccessValidationResult or a FailureValidationResult)

Default Values

The DataGrid provides the following default ValidationRuleDefinition:

Key

length

range

required

They each offer default validation rule options:

length: To validate if a string’s length is longer or equal to min and smaller or equals to max.

Property

Type

Description

min

number

The minimum value used to validate the string’s length.

max

number

The maximum value used to validate the string’s length.

errorMessage

string

The error message, if any.

range: To validate if a value is greater or equal to min and smaller or equals to max.

Property

Type

Description

min

number

The minimum value used to validate the provided value.

max

number

The maximum value used to validate the provided value.

errorMessage

string

The error message, if any.

required: To validate if a value is null, undefined or an empty string.

Property

Type

Description

errorMessage

string

The error message, if any.

Example

A ValidationRuleDefinitionCollection must be given to the DatagridOptions.validationRuleDefinitions property.

const validationRuleDefinitions = {

  "greaterZero": { validate: validateGreaterZero },   //custom ValidationRuleDefinition

  "lessTen": { validate: validateLessTen },   //custom ValidationRuleDefinition

  "range": { options: { min: 0, max: 15, errorMessage: "Value must be between 0 and 15." } }   //redefine default ValidationRuleDefinition

};

The greaterZero, lessThan and range keys must be found in the ColumnDefinition.validationRules property for each column where a validation of this type is required.

A partial type/interface is an object in which properties are optional.