Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface FormHookOutput<Data, Meta>

Type parameters

  • Data

  • Meta = {}

Hierarchy

  • FormHookOutput

Index

Properties

data

data: Data

The current data object

meta

meta: Meta

Forms meta data

Methods

bind

  • bind<Key>(field: Key): { aria-label: string; id: string; name: Key; value: Data[Key]; onChange: any }
  • Bind to a field, used to quickly setup input tags.

    For example <input {...bind('field')} />

    Type parameters

    • Key: string | number | symbol

    Parameters

    • field: Key

      The field to bind this input to.

    Returns { aria-label: string; id: string; name: Key; value: Data[Key]; onChange: any }

    • aria-label: string

      Aria label for the field. Is either the name or the name merged with the supplied ariaModel.

    • id: string

      Same as the aria label.

    • name: Key

      The fields name.

    • value: Data[Key]

      The current value of the field.

    • onChange:function
      • onChange(e: any): void
      • THe default on change handler. Takes e.target.value and uses it as the new field value.

        Parameters

        • e: any

        Returns void

changed

  • changed(field?: keyof Data): boolean
  • Has the value changed from its original.

    Parameters

    • Optional field: keyof Data

      (Optional) limit search to a single field.

    Returns boolean

clear

  • clear(): void

controlledInput

  • controlledInput<Key, Render>(field: Key, fieldOptions?: { onChange?: any; render?: any }): ControlledInput<Data, Key, Render>
  • Returns an object of functions to be used with an input, see ControlledInput

    Type parameters

    • Key: string | number | symbol

    • Render: unknown = Data[Key]

    Parameters

    • field: Key
    • Optional fieldOptions: { onChange?: any; render?: any }

    Returns ControlledInput<Data, Key, Render>

formBind

  • formBind(): { onSubmit: any }

label

  • label<Key>(field: Key): { htmlFor: string }
  • Returns the required fields for a label.

    Type parameters

    • Key: string | number | symbol

    Parameters

    • field: Key

    Returns { htmlFor: string }

    • htmlFor: string

onChange

  • onChange<Key>(field: Key, handler: (value: string) => Data[Key]): void
  • Add an onChange handler for the given field.

    Works with bind.

    For more control use a controlledInput with onChange and onRender functions.

    Type parameters

    • Key: string | number | symbol

    Parameters

    • field: Key
    • handler: (value: string) => Data[Key]
        • (value: string): Data[Key]
        • Parameters

          • value: string

          Returns Data[Key]

    Returns void

onSubmit

  • onSubmit(cb: (data: Data, meta: Meta) => void): void
  • The function passed as a callback will be called when the form is submitted.

    Parameters

    • cb: (data: Data, meta: Meta) => void

      Callback function that is passed the current data object when the form is submitted.

        • (data: Data, meta: Meta): void
        • Parameters

          • data: Data
          • meta: Meta

          Returns void

    Returns void

set

  • set(data: Partial<Data>, meta?: Partial<Meta>): void
  • Set the data to the supplied data.

    Parameters

    • data: Partial<Data>

      The new data object to use.

    • Optional meta: Partial<Meta>

    Returns void

submit

  • submit(): void
  • Submit the form. Useful if you need a button outside the form to submit the value.

    Make sure to bind the form aswell incase it is submitted by another means

    Returns void

valid

  • valid(field?: keyof Data): boolean
  • Check the validation status of the form or field.

    Parameters

    • Optional field: keyof Data

      (Optional), if supplied the validation status of the given field will be returned, otherwise the whole forms status will be returned.

    Returns boolean

validate

  • validate<Key>(field: Key, validator: (value: Data[Key], data: Data, meta: Meta) => boolean): void
  • Defines a validator for the form.

    Type parameters

    • Key: string | number | symbol

    Parameters

    • field: Key

      The field to validate.

    • validator: (value: Data[Key], data: Data, meta: Meta) => boolean

      The function to validate the field, should return a boolean for valid status.

        • (value: Data[Key], data: Data, meta: Meta): boolean
        • Parameters

          • value: Data[Key]
          • data: Data
          • meta: Meta

          Returns boolean

    Returns void

Generated using TypeDoc