Skip to content

Commit a0257ec

Browse files
committed
Docs about resetAndClearErrors() Form helper
see inertiajs/inertiajs.com#435
1 parent 47e82db commit a0257ec

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/guide/forms.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,45 @@ $form.reset('field', 'anotherfield')
653653

654654
:::
655655

656+
@available_since core=2.0.15
657+
658+
Sometimes, you may want to restore your form fields to their default values and clear any validation errors at the same time. Instead of calling `reset()` and `clearErrors()` separately, you can use the `resetAndClearErrors()` method, which combines both actions into a single call.
659+
660+
:::tabs key:frameworks
661+
662+
== Vue
663+
```js
664+
// Reset the form and clear all errors...
665+
form.resetAndClearErrors()
666+
667+
// Reset specific fields and clear their errors...
668+
form.resetAndClearErrors('field', 'anotherfield')
669+
```
670+
671+
== React
672+
673+
```jsx
674+
const { resetAndClearErrors } = useForm({ ... })
675+
676+
// Reset the form and clear all errors...
677+
resetAndClearErrors()
678+
679+
// Reset specific fields and clear their errors...
680+
resetAndClearErrors('field', 'anotherfield')
681+
```
682+
683+
== Svelte 4|Svelte 5
684+
685+
```js
686+
// Reset the form and clear all errors...
687+
$form.resetAndClearErrors()
688+
689+
// Reset specific fields and clear their errors...
690+
$form.resetAndClearErrors('field', 'anotherfield')
691+
```
692+
693+
:::
694+
656695
If your form's default values become outdated, you can use the `defaults()` method to update them. Then, the form will be reset to the correct values the next time the `reset()` method is invoked.
657696

658697
:::tabs key:frameworks

0 commit comments

Comments
 (0)