Interface ValidatorOptions

Describes the settings of a validator.

Type parameters

Type parameter Description
TInputs: InputGroupContent

the type of the validator's input structure.

TDomainValue

the type of the validator's domain interpretation of the inputs.

TParseError

the type of the validator's description of input format error.

TDomainError

the type of the validator's description of the domain value error.

domain

domain: TaskAction<TDomainValue, Falsy | ValidationFailure<TDomainError, TDomainValue>, void>

Specifies validation for the domain value that is obtained by parsing the input value.

name

name: undefined | string

Debug-friendly name that can be back-queried from the state instance.

validateOnInput

validateOnInput: undefined | false | true

If true, input action on the inputs contributing to this validator will cause the validator to validate. Otherwise, the default behavior is to only validate when a contributing input is confirmed.

enabled

  • enabled(this: Validator<TInputs, TDomainValue, TParseError, TDomainError>, self: Validator<TInputs, TDomainValue, TParseError, TDomainError>): boolean
  • Specifies whether the domain validation should take place. This has consequences when automatically validating input as a result of confirming inputs and submitting a form.

    see

    Input.confirm

    see

    Form.submit

    Parameters

    • this: Validator<TInputs, TDomainValue, TParseError, TDomainError>
    • self: Validator<TInputs, TDomainValue, TParseError, TDomainError>

      reflects back the validator instance when specifying an arrow function as predicate.

    Returns boolean

format

  • format(domainValue: TDomainValue): InferInputGroupValue<TInputs>
  • Specifies how a domain value might be formatted back into the input value given by this validator. This must be a pure, synchronous function returning a corresponding shape of input value from the domain value.

    Parameters

    • domainValue: TDomainValue

      The domain value to format as input value.

    Returns InferInputGroupValue<TInputs>

parse

  • parse(value: InferInputGroupValue<TInputs>): Falsy | object | ValidationFailure<TParseError, InferInputGroupValue<TInputs>>
  • Specifies how the input value should be converted to a domain value, as well as any error that is encountered while parsing. This must be a pure, synchronous function returning one of the following:

    • an arbitrary domain value in an object with the "domain" key, or
    • an arbitrary error value in an "error" key. Optionally, an additional "correction" key may be provided to suggest possible correction of the input.
    • a falsy value. This will taken to mean successful parsing and that the domain value should be the same as the input value.

    Parameters

    • value: InferInputGroupValue<TInputs>

    Returns Falsy | object | ValidationFailure<TParseError, InferInputGroupValue<TInputs>>

Generated using TypeDoc