From 498a4c1fe5d30f51bc875172811b5683609b4be9 Mon Sep 17 00:00:00 2001 From: riefive Date: Mon, 10 Nov 2025 13:58:58 +0700 Subject: [PATCH] feat(encounter): enhance form submission handling with detailed logging and fallback mechanism --- app/components/app/encounter/entry-form.vue | 27 ++++++++++++++++++++- app/components/content/encounter/entry.vue | 20 ++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/components/app/encounter/entry-form.vue b/app/components/app/encounter/entry-form.vue index c4ada1db..9c24a0c6 100644 --- a/app/components/app/encounter/entry-form.vue +++ b/app/components/app/encounter/entry-form.vue @@ -42,7 +42,7 @@ const emit = defineEmits<{ }>() // Validation schema -const { handleSubmit, errors, defineField } = useForm({ +const { handleSubmit, errors, defineField, meta } = useForm({ validationSchema: toTypedSchema(IntegrationEncounterSchema), }) @@ -154,8 +154,33 @@ const onSubmit = handleSubmit((values) => { const formRef = ref(null) function submitForm() { + console.log('🔵 submitForm called, formRef:', formRef.value) + console.log('🔵 Form values:', { + doctorId: doctorId.value, + subSpecialistId: subSpecialistId.value, + registerDate: registerDate.value, + paymentType: paymentType.value, + }) + console.log('🔵 Form errors:', errors.value) + console.log('🔵 Form meta:', meta.value) + + // Trigger form submit using native form submit + // This will trigger validation and onSubmit handler if (formRef.value) { + console.log('🔵 Calling formRef.value.requestSubmit()') formRef.value.requestSubmit() + } else { + console.warn('⚠️ formRef.value is null, cannot submit form') + // Fallback: directly call onSubmit handler + // Create a mock event object + const mockEvent = { + preventDefault: () => {}, + target: formRef.value || {}, + } as SubmitEvent + + // Call onSubmit directly + console.log('🔵 Calling onSubmit with mock event') + onSubmit(mockEvent) } } diff --git a/app/components/content/encounter/entry.vue b/app/components/content/encounter/entry.vue index 8b88c388..78297754 100644 --- a/app/components/content/encounter/entry.vue +++ b/app/components/content/encounter/entry.vue @@ -269,6 +269,24 @@ async function handleEvent(menu: string, value?: any) { } } +// Handle save button click +function handleSaveClick() { + console.log('🔵 handleSaveClick called') + console.log('🔵 formRef:', formRef.value) + console.log('🔵 isSaveDisabled:', isSaveDisabled.value) + console.log('🔵 selectedPatient:', selectedPatient.value) + console.log('🔵 selectedPatientObject:', selectedPatientObject.value) + console.log('🔵 isSaving:', isSaving.value) + console.log('🔵 isLoadingDetail:', isLoadingDetail.value) + + if (formRef.value && typeof formRef.value.submitForm === 'function') { + console.log('🔵 Calling formRef.value.submitForm()') + formRef.value.submitForm() + } else { + console.error('❌ formRef.value is null or submitForm is not a function') + } +} + /** * Validate SEP number */ @@ -745,7 +763,7 @@ onMounted(async () => { type="button" class="h-[40px] min-w-[120px] text-white" :disabled="isSaveDisabled" - @click="formRef?.submitForm()" + @click="handleSaveClick" >