From 4a25a12390f8ecae83c1081c89eba99a8fda14f8 Mon Sep 17 00:00:00 2001 From: Romain Hamel Date: Tue, 2 Jan 2024 16:28:38 +0100 Subject: [PATCH] feat(Form): expose submit function (#1186) --- docs/content/3.forms/10.form.md | 5 ++++- src/runtime/components/forms/Form.vue | 3 +++ src/runtime/types/form.d.ts | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/content/3.forms/10.form.md b/docs/content/3.forms/10.form.md index 1dbd20a6..f5c53520 100644 --- a/docs/content/3.forms/10.form.md +++ b/docs/content/3.forms/10.form.md @@ -203,6 +203,9 @@ componentProps: ## API ::field-group + ::field{name="submit ()" type="Promise"} + Triggers form submission. + :: ::field{name="validate (path?: string, opts: { silent?: boolean })" type="Promise"} Triggers form validation. Will raise any errors unless `opts.silent` is set to true. :: @@ -217,5 +220,5 @@ componentProps: :: ::field{name="errors" type="Ref"} A reference to the array containing validation errors. Use this to access or manipulate the error information. - :: + :: :: diff --git a/src/runtime/components/forms/Form.vue b/src/runtime/components/forms/Form.vue index cc8fa2f6..9f8b5f8c 100644 --- a/src/runtime/components/forms/Form.vue +++ b/src/runtime/components/forms/Form.vue @@ -144,6 +144,9 @@ export default defineComponent({ errors.value = errs } }, + async submit () { + await onSubmit(new Event('submit')) + }, getErrors (path?: string) { if (path) { return errors.value.filter((err) => err.path === path) diff --git a/src/runtime/types/form.d.ts b/src/runtime/types/form.d.ts index 018c9c6c..70ece906 100644 --- a/src/runtime/types/form.d.ts +++ b/src/runtime/types/form.d.ts @@ -15,6 +15,7 @@ export interface Form { errors: Ref setErrors(errs: FormError[], path?: string): void getErrors(path?: string): FormError[] + submit(): Promise } export type FormSubmitEvent = SubmitEvent & { data: T }