File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -742,6 +742,50 @@ export default function () {
742
742
} ,
743
743
] }
744
744
/>
745
+ < P >
746
+ Sometimes, you may want to restore your form fields to their default values and clear any validation errors at{ ' ' }
747
+ the same time. Instead of calling < Code > reset()</ Code > and < Code > clearErrors()</ Code > separately, you can use the{ ' ' }
748
+ < Code > resetAndClearErrors()</ Code > method, which combines both actions into a single call.
749
+ </ P >
750
+ < TabbedCode
751
+ examples = { [
752
+ {
753
+ name : 'Vue' ,
754
+ language : 'js' ,
755
+ code : dedent `
756
+ // Reset the form and clear all errors...
757
+ form.resetAndClearErrors()
758
+
759
+ // Reset specific fields and clear their errors...
760
+ form.resetAndClearErrors('field', 'anotherfield')
761
+ ` ,
762
+ } ,
763
+ {
764
+ name : 'React' ,
765
+ language : 'js' ,
766
+ code : dedent `
767
+ const { resetAndClearErrors } = useForm({ ... })
768
+
769
+ // Reset the form and clear all errors...
770
+ resetAndClearErrors()
771
+
772
+ // Reset specific fields and clear their errors...
773
+ resetAndClearErrors('field', 'anotherfield')
774
+ ` ,
775
+ } ,
776
+ {
777
+ name : 'Svelte' ,
778
+ language : 'js' ,
779
+ code : dedent `
780
+ // Reset the form and clear all errors...
781
+ $form.resetAndClearErrors()
782
+
783
+ // Reset specific fields and clear their errors...
784
+ $form.resetAndClearErrors('field', 'anotherfield')
785
+ ` ,
786
+ } ,
787
+ ] }
788
+ />
745
789
< P >
746
790
If your form's default values become outdated, you can use the < Code > defaults()</ Code > method to update them.
747
791
Then, the form will be reset to the correct values the next time the < Code > reset()</ Code > method is invoked.
You can’t perform that action at this time.
0 commit comments