diff --git a/src/components/JsonSchemaForm.vue b/src/components/JsonSchemaForm.vue index cac2739..aca1e33 100644 --- a/src/components/JsonSchemaForm.vue +++ b/src/components/JsonSchemaForm.vue @@ -2,16 +2,30 @@ import Form from "@rjsf/core"; import validator from "@rjsf/validator-ajv8"; import { applyPureReactInVue } from "veaury"; +import { FormEvent } from "react"; +import useMessenger from "@/message/messenger.composable"; const VeauryForm = applyPureReactInVue(Form); defineProps<{ schema: any; data: any; - onChange?: () => {}; - onSubmit?: () => {}; - onError?: () => {}; + onChange?: (event: FormEvent, fieldId: string) => {}; + onSubmit?: (event: FormEvent) => {}; }>(); + +type Error = { + message: string; + property: string; +}; + +const { alert } = useMessenger(); + +function onError(errors: Error[]) { + errors.forEach((error) => + alert(`${error.property.split(".").pop()} ${error.message}`, "error"), + ); +}