reset

Reset the entire form state and fields references. There are optional arguments to allow partial form state reset.

<T>(values?: T, options?: Record<string, boolean>) => void

Props


Reset has the ability to retain formState. Here are the options you may use:

NameTypeDescription
valuesObjectAn optional object to reset form values, and it's recommended to provide the entire defaultValues when supplied
opions.keepErrorsbooleanAll errors will remain. This will not guarantee with further user actions.
options.keepDirtybooleanRetain formState.dirtyFields().
opions.keepValuesbooleanForm input values will be unchanged.
options.keepTouchedbooleanRetain formState.touchedFields().
options.keepIsSubmittedbooleanisSubmitted state will be unchanged.
options.keepSubmitCountbooleansubmitCount state will be unchanged.

Uncontrolled example:

import { createForm } from "solid-hook-form" export const ExampleForm = () => { const form = createForm({ defaultValues: { firstName: "", lastName: "" } }) const { register, handleSubmit, reset } = form const onSubmit = (values) => { console.log(values) } return ( <form onSubmit={handleSubmit(onSubmit)}> <label>First name</label> <input {...register("firstName", { required: true })} /> <label>Last name</label> <input {...register("lastName")} /> <button type="submit">Submit</button> <button type="reset">Default Reset</button> <button type="button" onClick={() => reset()}> Custom Reset </button> </form> ) }