An IValidator implementation that represents a single validator for the value of an ValidatorsValueHostBase. 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.

Each instance depends on a few things, all passed into the constructor and treated as immutable.

  • IValidatorsValueHostBase - name, label, and values from the consuming system.
  • ValidatorConfig - The business logic supplies these rules to implement validation including Condition, Enabler, and error messages If the caller changes any of these, discard the instance and create a new one. The parent ValueHost will restore the state.

Implements

Constructors

Properties

errorMessageMissing: "***ERROR MESSAGE MISSING***" = '***ERROR MESSAGE MISSING***'

Accessors

  • get condition(): ICondition
  • Condition used to validate the data. Run by validate(), but only if the Validator is enabled (severity<>Off and Enabler == Match) The actual Condition instance is created by the caller and supplied in the ValidatorConfig. WhenCondition is a special case. When it is the condition returned, its child Condition is used here as the WhenCondition is more of a container to supply both condition and Enabler with conditions.

    Returns ICondition

  • get enabler(): null | ICondition
  • Condition used to enable or disable this validator based on rules. severity = Off takes precedence. WhenCondition is a special case. When it is the condition returned, its child Condition is used here as the WhenCondition is more of a container to supply both condition and Enabler with conditions.

    Returns null | ICondition

Methods

  • Participates in releasing memory. While not required, the idea is to be a more friendly participant in the ecosystem. Note that once called, expect null reference errors to be thrown if any other functions try to use them.

    Returns void

  • Resolves the errorMessage as a template - before it has its tokens processed. It uses several sources to get the template. The first to have text is used.

    1. Config.errorMessagel10n gets data from TextLocalizerService with Config.errorMessage as fallback
    2. Overridden Config.errorMessage or Config.errorMessage
    3. TextLocalizerService.getErrorMessage

    Returns string

    Error message from errorMessage property with localization applied if ErrorMessagel10n is setup.

  • Resolves the summaryMessage as a template - before it has its tokens processed. Falls back to use GetErrorMessageTemplate if Config doesn't supply a value.

    Returns string

    Error message from summaryMessage property with localization applied if SummaryMessagel10n is setup.

  • validate() found NoMatch. Update the IssueFound to show the current ConditionEvaluateResult and error messages.

    Parameters

    • issueFound: IssueFound

      this is a COPY of the IssueFound. Do not modify the actual instance as it is immutable.

    • valueHost: IValueHost

    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.

  • InstanceState is stored in ValueHost's InstanceState using its saveIntoInstanceStare/getFromInstanceState. Each entry needs to be associated with the errorCode of this Validator and have its own identifier for the value. This function creates a name to use with saveToStore and getFromStore.

    Parameters

    • identifier: string

    Returns string

  • Returns an entry from the ValueHostInstanceState.

    Often used to store values that override an entry in the ValidatorConfig. In that case, typical implementation is: let value = this.getFromInstanceState('identifier') ?? this.config.identifier;

    Parameters

    • identifier: string

      used together with the errorCode to form a key in the instanceState.

    Returns undefined | ValidTypesForInstanceStateStorage

    The value or undefined if the key is not stored in state.

  • Use to change the enabled flag. It overrides the value from ValidatorConfig.enabled. Use case: the list of validators on ValidatorsValueHostBase might change while the form is active. Add all possible cases to ValidatorsValueHostBase 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

  • Returns an array of 0 or more tokens supported by this MessageTokenSource. Each returned has the token supported (omitting {} so {Label} is "Label") and the value in its native data type (such as Date, number, or string). Supports these tokens: {Label} - the Config.label property verbatim {Value} - the native value in instanceState.Value. If null/undefined, the value in instanceState.LastRawValue. Plus any from the Condition in use.
    {DataType} - the name of the data type. Uses values registered with TextLocalizerService and LookupKey enum's strings as a fallback.

    Parameters

    Returns TokenLabelAndValue[]

Generated using TypeDoc v0.25.12