Installation
The @mantine/form package does not depend on any other libraries. You can use it with or without @mantine/core inputs:
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 the form onSubmit and onReset event handler. The onSubmit handler accepts as a second argument a function
that will be called with the errors object when validation fails.
onSubmitPreventDefault option
By default, event.preventDefault() is called on the form onSubmit handler.
If you want to change this behavior, you can pass the onSubmitPreventDefault option
to the useForm hook. It can have the following values:
always(default) - always callevent.preventDefault()never- never callevent.preventDefault()validation-failed- callevent.preventDefault()only if validation failed
Touched and dirty
UseFormReturnType
UseFormReturnType can be used when you want to pass the form as a prop to another component: