Class ValidatedInput

A shorthand for an input with a single validator validating the input value.

Type parameters

Type parameter Description
TInputValue

the input value

TDomainValue

the input validator's domain value.

TParseError

the input's parse error.

TDomainError

the input's domain error.

constructor

  • Instantiates a validated input.

    Parameters

    • defaultValue: TInputValue

      The input's default value. If using TypeScript, you can type this value exactly instead of parameterizing the generics fully.

    • Optional options: ValidatedInputOptions<TInputValue, TDomainValue, TParseError, TDomainError>

      The validated input options, which is a combination of the input options and the validator options.

    Returns ValidatedInput

boundsQuery

boundsQuery: BoundsQuery

defaultValue

defaultValue: TInputValue

The input's default value. If using TypeScript, you can type this value exactly instead of parameterizing the generics fully.

devOptions

devOptions: StateDevOptions

Development-time settings

focusState

focusState: FocusState

hoverState

hoverState: HoverState

options

options: ValidatedInputOptions<TInputValue, TDomainValue, TParseError, TDomainError>

The validated input options, which is a combination of the input options and the validator options.

validator

validator: Validator<Input<TInputValue>, TDomainValue, TParseError, TDomainError>

form

  • get form(): null | Form<any, any, any>
  • Return the singleton form that this input is associated to, only in the case where this input is indeed associated to that single form. Returns null if the input is not associated to any form or is associated to multiple forms.

    Returns null | Form<any, any, any>

forms

  • get forms(): Form<any, any, any>[]
  • Returns all forms associated with this input.

    Returns Form<any, any, any>[]

hasChanged

  • get hasChanged(): boolean
  • Returns true if the input value is different from the last confirmed value.

    Returns boolean

inputValue

  • get inputValue(): TValue
  • Gets the current input value. If the user has not touched the input, this is the same as the store value.

    Returns TValue

isBeingSubmitted

  • get isBeingSubmitted(): boolean
  • Returns true if any of the forms that this input belongs is being submitted.

    Returns boolean

isConfirmed

  • get isConfirmed(): boolean
  • Returns true if the user has ever confirmed the input.

    Returns boolean

isPending

  • get isPending(): boolean
  • Returns true if the input has put content without confirming it. Essentially means input() has been called without calling confirm().

    Returns boolean

isValidated

  • get isValidated(): boolean

name

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

    Returns null | string

normalizedInputValue

  • get normalizedInputValue(): TValue
  • Returns the input value, but normalized by the normalizer provided in the input options.

    Returns TValue

normalizedInputValueParseResult

  • Returns the parse result for the normalized form of the current input value.

    Returns ParseFailure<TInputValue, TParseError> | ParseSuccess<TDomainValue>

validators

  • get validators(): Validator<any, any, any, any>[]
  • Returns all validators associated with this input.

    Returns Validator<any, any, any, any>[]

value

  • get value(): TValue
  • Gets the store value. If the user has pending input, that value is not reflected here.

    Returns TValue

clear

  • clear(): void
  • Clears the current input value. This will make the current input value the same as the store value.

    Returns void

confirm

  • confirm(args?: undefined | object): Promise<void>
  • Commits the input value into the store as a consequence of a user action that confirms an input. For instance, this method should be called when the user blurs out of an input or hits enter on a single-line input.

    The value to confirm is the normalized by the normalizer provided in the input options.

    The method is no-op if the value to confirm is exactly the same as the value of the store and the input has been confirmed already.

    The input will ask its validators to (re-)trigger validation if the value is different from the store value. If the "revalidate" option is configured, the decision whether or not to validate completely depends on this predicate.

    see

    InputOptions.normalizer

    see

    InputOptions.revalidate

    see

    InputOptions.confirmCascade

    Parameters

    • Optional args: undefined | object

      Customizes the nature of the confirm interaction.

    Returns Promise<void>

formatDomainValue

  • formatDomainValue(value: TDomainValue): TInputValue
  • Formats the domain value as an input value. Shorthand for calling formatDomainValue on this validated input's validator.

    Parameters

    • value: TDomainValue

    Returns TInputValue

input

  • input(value: TInputValue): void
  • Sets the input value as a consequence of the user inputting a value.

    For input with choices, inputting a value will start a new query for possible choices.

    An input that is being submitted by a form will not respond to this method.

    Parameters

    • value: TInputValue

    Returns void

markAsConfirmed

  • markAsConfirmed(): void
  • Arbitrarily flag the input as having confirmed by the user.

    Returns void

normalizeValue

  • normalizeValue(value: TInputValue): TValue

requireDomainValue

  • requireDomainValue(): TDomainValue
  • Obtains the input's domain value assuming that the input can be parsed. Shorthand for accessing requireDomainValue on the validated input's validator.

    Returns TDomainValue

reset

  • reset(args?: undefined | object): void
  • Resets the user-confirmed flag. Optionally resets the input value to any arbitrary value.

    Parameters

    • Optional args: undefined | object

    Returns void

validate

  • validate(filter?: "input" | "confirm" | null): Promise<void>
  • Request validation on the input. This goes through all validators that are associated with the input.

    If a validator is not enabled (see the "enabled" validator option) initially, it is not validated but will be checked again after the first set of enabled validators have completed. You can exploit this behavior to write validators that are only enabled based on validity of other validators.

    see

    ValidatorOptions.enabled

    Parameters

    • Default value filter: "input" | "confirm" | null = null

    Returns Promise<void>

Generated using TypeDoc