Interface ValidatorConfig

Just the data that is used to describe one validator assigned to a ValueHost. It should not contain any supporting functions or services. It should be generatable from JSON, and simply gets typed to ValidatorConfig. This provides the backing data for each ValidatorInfo. When placed into the ValidatorInfo, it is treated as immutable and can be used as state in React. The server side could in fact supply this object via JSON, allowing the server's Model to dictate this. However, there are sometimes cases a business rule is client side only (parser error converting "abc" to number) and times when a business rule is server side only (looking for injection attacks for the purpose of logging and blocking.)

NOTE: extensions of this interface can implement IDisposable knowing that the Validator will call dispose() if supplied, during its own disposal.

interface ValidatorConfig {
    validatorType?: string;
    errorCode?: string;
    conditionConfig: null | ConditionConfig;
    conditionCreator?: ConditionCreatorHandler;
    enabled?: boolean | ((host) => boolean);
    severity?: ValidationSeverity | ((host) => ValidationSeverity);
    errorMessage?: null | string | ((host) => string);
    errorMessagel10n?: null | string;
    summaryMessage?: null | string | ((host) => string);
    summaryMessagel10n?: null | string;
}

Properties

validatorType?: string

The ValidatorType used by the ValidatorFactory. Leave it null or undefined to use the built-in Validator class.

errorCode?: string

Provides the error code associated with this instance. When unassigned, the Validator uses the ConditionType as the error code.

conditionConfig: null | ConditionConfig

ConditionConfig that allows the ConditionFactory to provide the Condition. Like all Configs in this system, this is expected to be immutable. Only use this when ConditionCreator is null.

conditionCreator?: ConditionCreatorHandler

Use to create the Condition instance yourself, especially to support implementations of ICondition that don't implement IConditionCore. Only use this when ConditionConfig is null.

Param: requester

Returns

enabled?: boolean | ((host) => boolean)

When false, validation is never run. This supersedes the Enabler too. Values:

  • true/false obviously.
  • undefined - tells the Validator to treat it as true. (Its value will not be updated as we want this to be immutable while the Config is assigned to the host.)
  • function - Provide a function that will return true or false, given the Validator as a parameter.

Type declaration

    • (host): boolean
    • Parameters

      Returns boolean

severity?: ValidationSeverity | ((host) => ValidationSeverity)

Resolves the Severity for when the Condition evaluates as NoMatch. Values:

  • ValidationSeverity enum. Set to Severe by default for conditions with Category=Require and DataTypeCheck.
  • Undefined - tells the Validator to treat it as Error.
  • function - Provide a function that will return the ValidationSeverity, given the Validator as a parameter.

Type declaration

errorMessage?: null | string | ((host) => string)

The error message "template" that will appear on screen when the condition is NoMatch. It can use tokens, which are resolved with current data at the time of validation. Tokens are resolved with Services.MessageTokenResolver. It should already be localized, except for the tokens. It can contain HTML tags if the platform supports them. In that case, be sure to use HTML encoded characters. The string shown to the actual user is stored in ValueHostInstanceState.errorMessage. Values:

  • String - The error message with tokens and optional HTML tags.
  • function - Returns the error message, given the Validator, allowing you to replace or customize the message during validation. The function must return a string, although an empty string is valid. When localization is setup in ErrorMessagel10n, the value can be set to '' so long as your TextLocalizerService ALWAYS returns the text. Otherwise, this should be the fallback. If you have setup defaults for error messages with TextLocalizerService, leave this null to use the default. Any value here supersedes default error messages.

Type declaration

    • (host): string
    • Parameters

      Returns string

errorMessagel10n?: null | string

Localization key for errorMessage. Its value will be matched to an entry made to ValidationServices.TextLocalizerService, specific to the active culture. If setup and no entry was found in TextLocalizerService, the value from the errorMessage property is used.

summaryMessage?: null | string | ((host) => string)

Variation of the errorMessage intended to be displayed in a Validation Summary area. A summary is usually not near the field with the error. As a result, it helps to shape the message differently, usually by including the Label token. "{Label} is required." Values:

  • undefined and null - use the errorMessage as the template.
  • string - The error message with tokens and optional HTML tags.
  • function - Returns the error message, given the Validator, allowing you to replace or customize the message during validation. The function must return a string, although an empty string is valid. When localization is setup in SummaryMessagel10n, the value can be set to '' so long as your TextLocalizerService ALWAYS returns the text. Otherwise, this should be the fallback. If you have setup defaults for error messages with TextLocalizerService, leave this null to use the default. Any value here supersedes default error messages.

Type declaration

    • (host): string
    • Parameters

      Returns string

summaryMessagel10n?: null | string

Localization key for summaryMessage. Its value will be matched to an entry made to ValidationServices.TextLocalizerService, specific to the active culture. If setup and no entry was found in TextLocalizerService, the value from the errorMessage property is used.

Generated using TypeDoc v0.25.12