Installation
@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 form onSubmit and onReset event handler. onSubmit handler accepts as second argument a function
that will be called with 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 onSubmitPreventDefault option
to 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 form as a prop to another component: