exeform
  • Getting Started
  • Motivation
  • How It Works
  • Guides
    • Validation
    • Nested Structures
  • API
    • Form
    • Field
    • <Form />
    • useForm()
    • useField()
    • useCheckboxField()
    • useFieldValue()
    • useFormIsValid()
    • useFormContext()
Powered by GitBook
On this page
  • Properties
  • values
  • touched
  • errors
  • isValid
  • Methods
  • setFieldValue
  • setFieldTouched
  • setFieldError
  • touchAllFields
  • reset
  • subscribe

Was this helpful?

  1. API

Form

PreviousNested StructuresNextField

Last updated 3 years ago

Was this helpful?

A form object that contains the core library logic.

Properties

values

{ [key: string]: any }

This is a getter that returns current values

touched

{ [path: string]: boolean }

This is a getter that returns current touched. These values are needed when you want to show errors only after the user has touched the field. Usually marked as touched after calling the onBlur event. The values are flat, see .

errors

{ [path: string]: string }

This is a getter that returns current errors. The values are flat, see .

isValid

boolean

Methods

setFieldValue

setFieldValue(name: string, value: any): void

setFieldTouched

setFieldTouched(name: string, isTouched?: boolean): void

setFieldError

setFieldError(name: string, message: string): void

touchAllFields

touchAllFields(): void

Marks all fields with errors as touched and notifies all subscribers. This is useful after trying to submit a form.

reset

reset(): void

Sets the initial values for the values, touched, errors, and notifies all subscribers.

subscribe

Listener(): void
Unsubscribe(): void

subscribe(listener: Listener): Unsubscribe

Adds a subscriber and returns the unsubscribe function.

Please note: the list of subscribers remains unchanged until all subscribers are called. You should keep this in mind when one of the subscribers may initiate the unsubscription of another subscriber.

Sets a new value, starts validations and notifies all subscribers. For nested values, use name as described .

Marks the field as touched or not and notifies all subscribers. Value by default is true. For nested values, use name as described .

This sets an external error for the field, marks the field as touched, and notifies all subscribers. After changing the field value, this error is reset. For nested values, use name as described .

detail
detail
here
here
here