Interface IValidator

Represents a single validator for the value of an InputValueHost. It is stateless. Basically you want to call validate() to get all of the results of a validation, including ConditionEvaluateResult, error messages, severity, and more. That data ends up in the ValidationManager as part of its state, allowing the system consumer to know how to deal with the data of the ValueHost (save or not) and the UI to display the state.

interface IValidator {
    condition: ICondition;
    errorCode: string;
    conditionType: string;
    dispose(): void;
    getValuesForTokens(valueHost, valueHostResolver): TokenLabelAndValue[];
    validate(options): ValidatorValidateResult | Promise<ValidatorValidateResult>;
    setEnabled(enabled): void;
    tryValidatorSwap(businessLogicError): null | ValidatorValidateResult;
    gatherValueHostNames(collection, valueHostResolver): void;
}

Hierarchy (view full)

Implemented by

Properties

condition: ICondition

Exposes the Condition behind the validator

errorCode: string

Provides the error code associated with this instance. It uses ValidatorConfig.errorCode when assigned and ConditionType when not assigned.

conditionType: string

Gets the conditionType associated with the condition

Methods

  • If the user needs to abandon this instance, they should use this to clean up active resources (like timers) and to release memory that would stall the garbage collector from disposing this object. It should assign any object reference to undefined as a strong indicator that the object has been disposed.

    Returns void

  • Use to change the enabled option. It overrides the value from ValidatorConfig.enabled. Use case: the list of validators on InputValueHost might change while the form is active. Add all possible cases to InputValueHost and change their enabled flag here when needed. Also remember that you can use the enabler property on ValidatorConfig to automatically determine if the validator should run or not. Enabler may not be ideal in some cases though.

    Parameters

    • enabled: boolean

    Returns void

  • When ValueHost.setBusinessLogicError is called, it provides each entry to the existing list of Validators through this. This function determines if the businessLogicError is actually for the same error code as itself, and returns a ValidatorValidateResult, just like calling validate() itself. The idea is to use the UI's representation of the validator, including its error messages with its own tokens, instead of those supplied by the business logic.

    Parameters

    Returns null | ValidatorValidateResult

    if null, it did not handle the BusinessLogicError. If a ValidatorValidateResult, it should be used in the ValueHost's state of validation.

Generated using TypeDoc v0.25.12