diff --git a/packages/editor/src/Editor.vue b/packages/editor/src/Editor.vue index 95d5b96f1..3782d3940 100644 --- a/packages/editor/src/Editor.vue +++ b/packages/editor/src/Editor.vue @@ -70,6 +70,8 @@ @@ -17,7 +18,6 @@ diff --git a/packages/form/src/Form.vue b/packages/form/src/Form.vue index 4a721c45f..27056ee67 100644 --- a/packages/form/src/Form.vue +++ b/packages/form/src/Form.vue @@ -79,7 +79,7 @@ const props = withDefaults( }, ); -const emit = defineEmits(['change', 'field-input', 'field-change']); +const emit = defineEmits(['change', 'error', 'field-input', 'field-change']); const tMagicForm = ref>(); const initialized = ref(false); @@ -182,6 +182,8 @@ defineExpose({ await tMagicForm.value?.validate(); return native ? values.value : cloneDeep(toRaw(values.value)); } catch (invalidFields: any) { + emit('error', invalidFields); + const error: string[] = []; Object.entries(invalidFields).forEach(([, ValidateError]) => { @@ -191,6 +193,7 @@ defineExpose({ if (!field && message) error.push(`${message}`); }); }); + throw new Error(error.join('
')); } }, diff --git a/playground/src/pages/Editor.vue b/playground/src/pages/Editor.vue index 3633a5e2b..4b03e6fac 100644 --- a/playground/src/pages/Editor.vue +++ b/playground/src/pages/Editor.vue @@ -17,6 +17,7 @@ :moveable-options="moveableOptions" :auto-scroll-into-view="true" :stage-rect="stageRect" + @props-submit-error="propsSubmitErrorHandler" >