Class: ValidationContext

x2node-validators~ ValidationContext

Validation context used by the validator functions to access the validation environment and report errors.

new ValidationContext(recordTypes, recordTypeDesc, messageResolver, validationSets)

Note: The constructor is not accessible from the client code. Instances of the context are provided to the validators by the framework.
Parameters:
Name Type Description
recordTypes module:x2node-records~RecordTypesLibrary Record types library.
recordTypeDesc module:x2node-records~RecordTypeDescriptor Record type descriptor.
messageResolver module:x2node-validators~MessageResolver Message resolver for the validation error messages.
validationSets Set.<string> Validation sets.

Members


<readonly> containersChain :Array.<(Object|Array)>

Chain of parent container objects and array leading to the record element being currently validated. For the record itself, the chain is empty. For all other elements the first element in the chain is the record itself and the last element is the immediate container of the current element being validated.
Type:
  • Array.<(Object|Array)>

<readonly> currentPointer :module:x2node-pointers~RecordElementPointer

Pointer at the record element currently being validated.
Type:

<readonly> currentPropDesc :module:x2node-records~PropertyDescriptor

Property descriptor associated with the record element being validated, or null if record itself.
Type:

<readonly> recordTypeDesc :module:x2node-records~RecordTypeDescriptor

Record type descriptor.
Type:

<readonly> recordTypes :module:x2node-records~RecordTypesLibrary

Record types library.
Type:

Methods


addError(message [, params])

Add validation error associated with the record element currently being validated.
Parameters:
Name Type Argument Description
message string Validation error message id in curly braces or message template.
params Object.<string, *> <optional>
Validation error message parameters.

addErrorFor(ptr, message [, params])

Add validation error associated with the record element specified by a JSON pointer.
Parameters:
Name Type Argument Description
ptr string | module:x2node-pointers~RecordElementPointer The pointer.
message string Validation error message id in curly braces or message template.
params Object.<string, *> <optional>
Validation error message parameters.

getElementTitle(ptr)

Get title for the record element described by the pointer.
Parameters:
Name Type Description
ptr string | module:x2node-pointers~RecordElementPointer The pointer.
Returns:
The corresponding property or record type title.
Type
string

hasErrorsFor(ptr)

Tell if there are validation errors for the specified pointer. When the validation runs on a record it first validates the deepest record elements gradually proceeding to the top record, which is validates the last. Therefore, a validator can use this method to check for validity of any of the properties that are below the current one. Also, validators for a single record element are run in the order they are specified on the element (with the default ones first, followed by the custom ones).
Parameters:
Name Type Description
ptr string | module:x2node-pointers~RecordElementPointer The pointer.
Returns:
true if has errors.
Type
boolean

isEmpty(val)

Tell if the provided value is undefined or null. May be useful in validation function implementations that often need to perform this kind of a test and always have the context available.
Parameters:
Name Type Description
val * Value to test.
Returns:
true if empty.
Type
boolean

isValidationSet(setId)

Tell if the specified validation set active. Note that default validation set (set id "*") is always active.
Parameters:
Name Type Description
setId string Set id.
Returns:
true if the set is active.
Type
boolean