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().

Hierarchy (view full)

Constructors

Accessors

  • get category(): ConditionCategory
  • Helps identify the purpose of the Condition. Impacts:

    • Sort order of the list of Conditions evaluated by an Validator, placing Require first and DataTypeCheck second.
    • Sets InputValueHostConfig.requiresInput.
    • Sets ValidatorConfig.severity when undefined, where Require and DataTypeCheck will use Severe. Others will use Error. Many Conditions have this value predefined. However, all will let the user override it with ConditionConfig.category.

    Returns ConditionCategory

Methods

  • Implementation for IMessageTokenSource. Conditions havea number of values that are appropriate for tokens on the ConditionConfig. Examples:

    • In RangeCondition, Minimum and Maximum properties become {Mininum} and {Maximum} tokens.
    • In CompareToValueCondition, secondValueHostName property is the source for the {CompareTo} token. This implementation feels like it violates Single Responsibility pattern. But keeping this feature separate from conditions greatly increases complexity.

    Parameters

    Returns TokenLabelAndValue[]

    An array. If an empty array if there are no token to offer. This base class has no tokens to offer.

  • Converts the given value and lookup key using the provided conversion lookup key. If the conversion fails, a warning log is generated. Takes no action if the conversionLookupKey is null.

    Parameters

    • value: any

      The value to be converted.

    • valueLookupKey: undefined | null | string

      The lookup key associated with the value. Often this should be assigned to valueHost.getDataType().

    • conversionLookupKey: undefined | null | string

      The conversion lookup key to be used for conversion. Often this comes from conversionLookupKey or secondConversionLookupKey found on the Config object.

    • services: IValueHostsServices

      The services

    Returns {
        value?: any;
        lookupKey?: null | string;
        failed: boolean;
    }

    An object containing the converted value, lookup key, and a flag indicating if the conversion failed.

    • Optional value?: any
    • Optional lookupKey?: null | string
    • failed: boolean

Generated using TypeDoc v0.25.12