Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/content/docs/useform/setvalues.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ metaDescription: Update multiple React Hook Form field values at once using an o
sidebar: apiLinks
---

## \</> `setValues:` <TypeText>(value: Partial\<TFieldValues\> | ((data: TFieldValues) => Partial\<TFieldValues\>), options?: SetValueConfig) => void</TypeText>
## \</> `setValues:` <TypeText>(value: Partial\<TFieldValues\> | ((formValues: TFieldValues) => TFieldValues), options?: SetValueConfig) => void</TypeText>

This function allows you to dynamically set multiple field values at once and have the options to validate and update the form state. It also accepts a callback function that receives the current form values, making it easy to derive the next state from the existing one.

### Props

---

| Name | | Description |
| ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value`<br/><TypeText>Partial\<TFieldValues\> \| (data: TFieldValues) => Partial\<TFieldValues\></TypeText> | | An object containing the field values to update, or a callback function that receives the current form values and returns the updated values. This argument is required. |
| `options` | `shouldValidate`<br/><TypeText>boolean</TypeText> | <ul><li>Whether to compute if your input is valid or not (subscribed to <TypeText>errors</TypeText>).</li><li>Whether to compute if your entire form is valid or not (subscribed to <TypeText>isValid</TypeText>).</li></ul> |
| | `shouldDirty`<br/><TypeText>boolean</TypeText> | <ul><li>Whether to compute if your input is dirty or not against your `defaultValues` (subscribed to <TypeText>dirtyFields</TypeText>).</li><li>Whether to compute if your entire form is dirty or not against your `defaultValues` (subscribed to <TypeText>isDirty</TypeText>).</li></ul> |
| | `shouldTouch`<br/><TypeText>boolean</TypeText> | Whether to set the updated inputs to be touched. |
| Name | | Description |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value`<br/><TypeText>Partial\<TFieldValues\> \| (formValues: TFieldValues) => TFieldValues</TypeText> | | An object containing the field values to update, or a callback function that receives the current form values and returns the next form values. This argument is required. |
| `options` | `shouldValidate`<br/><TypeText>boolean</TypeText> | <ul><li>Whether to compute if your input is valid or not (subscribed to <TypeText>errors</TypeText>).</li><li>Whether to compute if your entire form is valid or not (subscribed to <TypeText>isValid</TypeText>).</li></ul> |
| | `shouldDirty`<br/><TypeText>boolean</TypeText> | <ul><li>Whether to compute if your input is dirty or not against your `defaultValues` (subscribed to <TypeText>dirtyFields</TypeText>).</li><li>Whether to compute if your entire form is dirty or not against your `defaultValues` (subscribed to <TypeText>isDirty</TypeText>).</li></ul> |
| | `shouldTouch`<br/><TypeText>boolean</TypeText> | Whether to set the updated inputs to be touched. |

<Admonition type="important" title="Rules">

- When using the callback form, the function receives a snapshot of the current form values and should return only the fields you want to update.
- When using the callback form, the function receives a snapshot of the current form values and should return the next form values.

- This method does not reset the form. Use [`reset`](/docs/useform/reset) if you need to reinitialize `defaultValues`.

Expand Down
Loading