From d4b6147fcceb7ff9cebe1586bb3094b10f50acb5 Mon Sep 17 00:00:00 2001 From: Romain Hamel Date: Sun, 18 Feb 2024 11:11:07 +0100 Subject: [PATCH] fix(Form): return false when silent validation fails (#1371) --- src/runtime/components/forms/Form.vue | 5 ++++- src/runtime/types/form.d.ts | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/runtime/components/forms/Form.vue b/src/runtime/components/forms/Form.vue index b5e8e0b1..27fd0baa 100644 --- a/src/runtime/components/forms/Form.vue +++ b/src/runtime/components/forms/Form.vue @@ -109,11 +109,14 @@ export default defineComponent({ errors.value = await getErrors() } - if (!opts.silent && errors.value.length > 0) { + if (errors.value.length > 0) { + if (opts.silent) return false + throw new FormException( `Form validation failed: ${JSON.stringify(errors.value, null, 2)}` ) } + return props.state } diff --git a/src/runtime/types/form.d.ts b/src/runtime/types/form.d.ts index 70ece906..93f62897 100644 --- a/src/runtime/types/form.d.ts +++ b/src/runtime/types/form.d.ts @@ -10,7 +10,8 @@ export interface FormErrorWithId extends FormError { } export interface Form { - validate(path?: string, opts?: { silent?: boolean }): Promise + validate(path?: string, opts?: { silent?: true }): Promise; + validate(path?: string, opts?: { silent?: false }): Promise; clear(path?: string): void errors: Ref setErrors(errs: FormError[], path?: string): void