You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| errors |`Record<string, string>`| The first error message of each field, the object keys are the fields names |
118
-
| meta |`Record<string, boolean>`| An aggregate of the [FieldMeta](/api/field#fieldmeta) for the fields within the form |
119
-
| values |`Record<string, any>`| The current field values |
120
-
| isSubmitting |`boolean`| True while the submission handler for the form is being executed |
121
-
| validate |`Function`| Validates the form |
122
-
| handleSubmit |`(cb: Function) => Function`| Creates a submission handler that disables the native form submissions and executes the callback if the validation passes |
123
-
| handleReset |`Function`| Resets and form and executes any `onReset` listeners on the component |
124
-
| submitForm |`Function`| Validates the form and triggers the `submit` event on the form, useful for non-SPA applications |
| errors |`Record<string, string>`| The first error message of each field, the object keys are the fields names |
118
+
| meta |`Record<string, boolean>`| An aggregate of the [FieldMeta](/api/field#fieldmeta) for the fields within the form |
119
+
| values |`Record<string, any>`| The current field values |
120
+
| isSubmitting |`boolean`| True while the submission handler for the form is being executed |
121
+
| validate |`Function`| Validates the form |
122
+
| handleSubmit |`(cb: Function) => Function`| Creates a submission handler that disables the native form submissions and executes the callback if the validation passes |
123
+
| handleReset |`Function`| Resets and form and executes any `onReset` listeners on the component |
124
+
| submitForm |`Function`| Validates the form and triggers the `submit` event on the form, useful for non-SPA applications |
125
+
| setFieldError |`Function`| Sets an error message on a field |
126
+
| setErrors |`Function`| Sets error message for the specified fields |
127
+
| setFieldValue |`Function`| Sets a field's value, triggers validation |
128
+
| setValues |`Function`| Sets the specified fields values, triggers validation on those fields |
125
129
126
130
Check the sample above for rendering with scoped slots
Copy file name to clipboardExpand all lines: docs/content/guide/handling-forms.md
+96-1Lines changed: 96 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -372,14 +372,109 @@ You can use `validateOnMount` prop present on the `<Form />` component to force
372
372
373
373
The `initialValues` prop on both the `<Form />` component and `useForm()` function can reactive value, meaning you can change the initial values after your component was created/mounted which is very useful if you are populating form fields from external API.
374
374
375
-
Note that **only the pristine fields will be updated**. In other words, **only the fields that were not manipulated by the user will be updated**.
375
+
Note that **only the pristine fields will be updated**. In other words, **only the fields that were not manipulated by the user will be updated**. For information on how to set the values for all fields regardless of their dirty status check the following [Setting Form Values section](#setting-form-values)
376
376
377
377
<doc-tiptitle="Composition API">
378
378
379
379
If you are using the composition API with `setup` function, you could create the `initialValues` prop using both [**reactive()**](https://v3.vuejs.org/api/basic-reactivity.html#reactive) and [**ref()**](https://v3.vuejs.org/api/refs-api.html#ref). vee-validate handles both cases.
380
380
381
381
</doc-tip>
382
382
383
+
## Setting Form Values
384
+
385
+
You can set any field's value using either `setFieldValue` or `setValues`, both methods are exposed on the `<Form />` component scoped slot props, and in `useForm` return value, and as instance methods if so you can call them with template `$refs` and for an added convenience you can call them in the submit handler callback.
386
+
387
+
**Using scoped slot props**
388
+
389
+
```vue
390
+
<Form v-slot="{ setFieldValue, setValues }">
391
+
<Field name="email" as="input">
392
+
<ErrorMessage name="email" />
393
+
394
+
<Field name="password" as="input">
395
+
<ErrorMessage name="password" />
396
+
397
+
<button type="button" @click="setFieldValue('email', 'test')">Set Field Value</button>
Note that setting any field's value using this way will trigger validation
477
+
383
478
## Setting Errors Manually
384
479
385
480
Quite often you will find yourself unable to replicate some validation rules on the client-side due to natural limitations. For example a `unique` email validation is complex to implement on the client-side, which is why the `<Form />` component and `useForm()` function allow you to set errors manually.
0 commit comments