Module Conditions/ConcreteConditions/WhenCondition

Specialized condition used to enable/disable another condition. It is a wrapper around another condition that evaluates the other condition only when its own enabler condition is ConditionEvaluationResult.Match.

Example: Only use requireText when the regular expression pattern is matched against another valuehost

builder.input('fieldname')
.when((enabler)=>enabler.regExp('pattern', false, 'anotherValueHost')),
(child)=>child.requireText());

Note that the enabler condition is not passed the current valuehost to evaluate. It is passed null, and the enabler condition should be configured to get its own value host because it is rare that the enabler condition should be based on the same valuehost as the child condition.

The Validator.validate function will call the enabler and child conditions directly, bypassing the WhenCondition.evaluate function and its limitation of no conditions that return a promise. Any condition where WhenCondition is a child will use the WhenCondition.evaluate function and retain its limitation of no conditions that return a promise.

ALERT: ConditionType=When is NEVER used as a Validator's errorCode. The child condition's ConditionType is used as the errorCode instead. This is maintained both in this class's conditionType and in resolveErrorCode().

Index

Classes

Interfaces

Generated using TypeDoc v0.25.12