diff --git a/src/components/FormV2/PdapFormV2.vue b/src/components/FormV2/PdapFormV2.vue index ab5a1ef..2d1907c 100644 --- a/src/components/FormV2/PdapFormV2.vue +++ b/src/components/FormV2/PdapFormV2.vue @@ -35,7 +35,7 @@ const { defaultValues, error, schema } = withDefaults( ); // Emits -const emit = defineEmits(['submit', 'change']); +const emit = defineEmits(['submit', 'change', 'error']); // Constants const errorMessage = ref(error); @@ -76,6 +76,7 @@ function resetForm() { async function submit(e: Event) { // Check form submission const isValidSubmission = await v$.value.$validate(); + if (!isValidSubmission) emit('error', v$); if (isValidSubmission) { // Emit submit event (spread to new object to create new object, this allows us to reset `values` without messing with the data returned) emit('submit', { ...values.value }, e); diff --git a/src/demo/pages/FormV2Demo.vue b/src/demo/pages/FormV2Demo.vue index 243b861..5f3c3fc 100644 --- a/src/demo/pages/FormV2Demo.vue +++ b/src/demo/pages/FormV2Demo.vue @@ -4,6 +4,7 @@ id="form-id" name="form-name" :schema="SCHEMA" + @error="(v$) => console.debug({ v$ })" @submit="(values) => console.log({ values })" @change="(values, event) => console.log({ values, event })" >