use-form
Installation
@asuikit/form package does not depend on any other libraries, you can use it with or without @asuikit/core inputs:
Install with npm:
Install with yarn:
Usage
API overview
All examples below use the following example use-form hook.
Values
List items
Validation
Errors
Validation errors occur when defined validation rules were violated, initialErrors were specified in useForm properties
or validation errors were set manually.
onReset and onSubmit
Wrapper function for form onSubmit and onReset event handler. onSubmit handler accepts as second argument a function
that will be called with errors object when validation fails.
Touched and dirty
getInputProps
form.getInputProps returns an object with value, onChange, onFocus, onBlur and error that should be spread on input.
As second parameter options can be passed.
- type: default- input. Needs to be configured to- checkboxif input requires- checkedto be set instead of- value.
- withError: default- type === 'input'. Specifies if the returned object contains an- errorproperty with- form.errors[path]value.
- withFocus: default- true. Specifies if the returned object contains an- onFocushandler. If disabled, the touched state of the form can only be used if all values are set with- setFieldValue.
UseFormReturnType
UseFormReturnType can be used when you want to pass form as a prop to another component: