Class Validator

Represents a state for form input validation. This includes bookkeeping of whether the validation has ever happened, what the most recent validation result was, and whether asynchronous validation is happening on right now.

Type parameters

Type parameter Description
TInputs: InputGroupContent

the type of the "input shape". This can be an input type, an object of inputs, an array of inputs, or a nested structure thereof, or a function returning such a structure.

TDomainValue

the type of the domain value that is extracted from the input value for domain validation.

TParseError

the type that describes the error when trying to parse the input value into a domain value.

TDomainError

the type that describes the error resulting from validating the domain value.

constructor

  • Instantiates a validator.

    see

    Input

    see

    InputGroup

    Parameters

    • inputs: MaybeConstant<function>

      The input whose values will be needed in validation. This can be any arbitrary structure of input states.

    • Default value validatorOptions: ValidatorOptions<TInputs, TDomainValue, TParseError, TDomainError> = {}

      Specifies additional options for the validator.

    Returns Validator

devOptions

devOptions: StateDevOptions

Development-time settings

hoverState

hoverState: HoverState

options

options: InputGroupOptions

Customizes input group behavior.

validatorOptions

validatorOptions: ValidatorOptions<TInputs, TDomainValue, TParseError, TDomainError>

Specifies additional options for the validator.

correction

  • get correction(): InferInputGroupValue<TInputs> | void
  • Returns the correctional input value. This correction may arise from the parsing or from the domain validation (the former is favoured). If there is no correctional value (either because the domain validator/parser didn't give any or because the validation succeeded), this returns void.

    Returns InferInputGroupValue<TInputs> | void

domainResult

  • get domainResult(): DomainResult<TDomainValue, TDomainError>
  • Gets the validator's latest domain validation result. Note that if domain validation has never been triggered, this returns a success.

    For a more conclusive check for input validity, use isConclusivelyValid and isConclusivelyInvalid.

    see

    isConclusivelyInvalid

    see

    isConclusivelyValid

    Returns DomainResult<TDomainValue, TDomainError>

domainValue

  • get domainValue(): TDomainValue | void
  • Gets the validator's domain value. This value is undefined if the input value cannot be parsed.

    Returns TDomainValue | void

error

  • get error(): ValidationError<InferInputGroupValue<TInputs>, TDomainValue, TParseError, TDomainError> | null
  • Gets the validator's most recent error result. This maybe a domain error or a parse error. Use the key "errorType" to discriminate the kind of error. When there is no error encountered, null is returned.

    Note that if the input value can be parsed and the domain validation has never been triggered, this returns null also. For a more conclusive check for input validity, use isConclusivelyValid and isConclusivelyInvalid.

    see

    isConclusivelyInvalid

    see

    isConclusivelyValid

    Returns ValidationError<InferInputGroupValue<TInputs>, TDomainValue, TParseError, TDomainError> | null

flattedInputs

  • get flattedInputs(): Input<any>[]
  • Returns a flattened array of inputs. The order of inputs is not guaranteed.

    Use structure to get the input structure as specified in the constructor including the subgroups, or inputs without the subgroups.

    see

    structure

    see

    inputs

    Returns Input<any>[]

flattenedStructure

  • Returns an array of the input group's structural items. Unlike [[flattenedInputs]], the subgroups are not broken down into inputs here.

    Returns (Input<any> | InputGroup<any>)[]

hasChangedInput

  • get hasChangedInput(): boolean
  • Returns true if any of the inputs that the validator depends on is in a "changed" state. Shorthand for checking that at least one input's hasChanged is true.

    see

    Input.hasChanged

    Returns boolean

hasUnconfirmedInput

  • get hasUnconfirmedInput(): boolean
  • Returns true if any of the inputs that the validator depends on has not been confirmed by the user.

    see

    Input.isConfirmed

    Returns boolean

inputValue

  • get inputValue(): InferInputGroupValue<TInputs>
  • Same as with value but each value is the current input value, not the confirmed input value.

    see

    value

    Returns InferInputGroupValue<TInputs>

inputs

  • get inputs(): InferInputGroupShape<TInputs>
  • Reflects the structure of inputs as provided in the constructor. If a function was passed in the constructor, it is evaluated here. Subgroups in the structures are collapsed into their structures.

    Use structure if you need the subgroups preserved. Use [[flattenedInputs]] if you don't care about the structure and just want the inputs in an array.

    see

    structure

    see

    [[flattenedInputs]]

    Returns InferInputGroupShape<TInputs>

isConclusive

  • get isConclusive(): boolean
  • Returns true if the validator is in a "conclusive" state: that is defined to mean that:

    • domain validation has happened
    • domain validation is not pending
    • the inputs the validator depend on have been confirmed.

    Returns boolean

isConclusivelyInvalid

  • get isConclusivelyInvalid(): boolean
  • Returns true if the input can be taken to be conclusively invalid. That is, it has either failed the parser, or it is in all of these states:

    • All inputs contributing to the validator have been confirmed.
    • It has been domain-validated at least once.
    • Domain validation is not pending.
    • There is some domain error.

    Returns boolean

isConclusivelyValid

  • get isConclusivelyValid(): boolean
  • Returns true if the input can be taken to be conclusively valid. That is, it is in all of these states:

    • All inputs contributing to the validator have been confirmed.
    • There is no parsing error.
    • It has been domain-validated at least once.
    • Domain validation is not pending.
    • There is no domain error.

    Returns boolean

isEnabled

  • get isEnabled(): any
  • Returns true if the validator is enabled for automatic validation. When this value is true,

    Returns any

isValidationPending

  • get isValidationPending(): boolean
  • Returns true if asynchronous domain validation is currently happening.

    Returns boolean

isVirgin

  • get isVirgin(): boolean
  • Returns true if the validator is "virgin": this is defined as follows:

    • For a validator validating on confirmed inputs: this should

    Returns boolean

name

  • get name(): null | string
  • Returns the UI state's debug name.

    Returns null | string

nestedValidators

  • Returns the "nested" validators: these are the other validators that also depend on one of the inputs this validator is depending on.

    Returns Validator[]

normalizedInputValue

  • get normalizedInputValue(): InferInputGroupValue<TInputs>
  • Same as with value but each value is the current input value, normalized by each input's normalizer.

    see

    value

    Returns InferInputGroupValue<TInputs>

parseResult

  • get parseResult(): ParseResult<InferInputGroupValue<TInputs>, TParseError, TDomainValue>
  • Gets validator's input parsing result. Use the "isError" key to discriminate between a successful parse (which will give you the domain value) and a failed parse (which will give you the parse error).

    Returns ParseResult<InferInputGroupValue<TInputs>, TParseError, TDomainValue>

promise

  • get promise(): null | Promise<void>
  • Returns the promise that resolves when the validation task is complete.

    Returns null | Promise<void>

structure

  • get structure(): TInputs
  • Returns the structure of the input group. If the input structure contains subgroups, the subgroups are preserved here.

    Use inputs to get the input structure without subgroups.

    Use [[flattenedInputs]] to get an array of inputs whose order does not matter.

    see

    flattedInputs

    see

    inputs

    Returns TInputs

value

  • get value(): InferInputGroupValue<TInputs>
  • Returns a structure of confirmed input value that corresponds to the input structure passed to the constructor. For instance, if the constructor was instantiated with { a : someInput, b: someOuterInput }, the value here will also have the keys a and b whose value are the respective input values.

    see

    inputValue

    Returns InferInputGroupValue<TInputs>

confirm

  • confirm(args: object): void
  • Batch-confirm the inputs using the value that is provided in the group. Note that unlike individually confirming an input, this does not permit an option to advance the focus to the "next" input.

    Parameters

    • args: object

    Returns void

formatDomainValue

  • formatDomainValue(domainValue: TDomainValue): InferInputGroupValue<TInputs>
  • Format a domain value into an input value. This can be used to turn the domain correction into meaningful input values.

    Parameters

    • domainValue: TDomainValue

      Domain value to format.

    Returns InferInputGroupValue<TInputs>

parse

  • parse(value: InferInputGroupValue<TInputs>): ParseResult<InferInputGroupValue<TInputs>, TParseError, TDomainValue>
  • Try parsing an input value.

    Parameters

    • value: InferInputGroupValue<TInputs>

      value to parse. This must match the value structure implied by the input structure.

    Returns ParseResult<InferInputGroupValue<TInputs>, TParseError, TDomainValue>

requireDomainValue

  • requireDomainValue(): TDomainValue
  • Gets the validator's domain value, assuming that the parsing has succeeded. Use this to bypass checking for successful parse, but it will throw an error if the parse has actually failed.

    Returns TDomainValue

reset

  • reset(args?: undefined | object): void
  • Batch-reset the inputs using the value that is provided in the group. This is the same as calling reset on the individual input instances.

    Parameters

    • Optional args: undefined | object

    Returns void

validate

  • validate(): Promise<void>
  • Triggers validation.

    If the input cannot be parsed, this is no-op. If there is pending validation from the previous trigger, that previous validation is canceled. While validation is going on, if the input value has changed such that it now cannot be parsed, the pending validation is canceled.

    Returns Promise<void>

Generated using TypeDoc