ZUI

Search documentation

Find a page or a heading.

Form

A form built from Field and a form library, such as react-hook-form.

Installation

Upstream's form item ships no files: a form is Field bound to a form library. So form installs nothing; install Field and the controls the form uses, and the form library:

bash
bash

Usage

Bind each control with react-hook-form's Controller, and draw it in a Field that is invalid while its value is, with a FieldError of the value's error:

tsx
tsx

A schema library plugs in as on the web, through resolver and @hookform/resolvers.

Differences from upstream

  • A control takes value, onChangeText and onBlur from field rather than {...field}: React Native's text field reports its text through onChangeText, not a DOM change event.
  • There is no <form> element to submit, so the submit button calls form.handleSubmit(onSubmit)() on its press, and a button outside the form needs no form attribute.
  • A label focuses its control through form.setFocus(name), where the web's htmlFor does it: React Native has no label element to tie to a control's id.
  • Field marks its state with invalid rather than data-invalid, as the Field page says.
  • The demo validates with each Controller's rules, where upstream's validates with a zod schema through zodResolver, so that installing it adds no schema library and no @hookform/resolvers. A schema plugs in through resolver as above.