setValue

This function allows you to dynamically set the value of a registered field and have the options to validate and update the form state.

(name: string, value: any, options?: SetValueOptions) => void

Props


NameTypeDescription
namestringForm field name.
valueanyThe value for the field. This argument is required and can not be undefined.
options.shouldValidatebooleanThis option will trigger validation for the target field.
options.shouldDirtybooleanThis option will update dirtyFields at the specified field level.
options.shouldTouchbooleanThis option will update touchedFields at the specified field level.
import { createForm } from "solid-hook-form" const ExampleForm = () => { const { register, setValue } = createForm({ defaultValues: { firstName: "" } }) return ( <form> <input {...register("firstName", { required: true })} /> <button onClick={() => { setValue("firstName", "Bill") }} > setValue </button> <button onClick={() => { setValue("firstName", "Luo", { shouldValidate: true, shouldDirty: true, }) }} > setValue options </button> </form> ) }