feat(encounter): enhance form submission handling with detailed logging and fallback mechanism
This commit is contained in:
@@ -42,7 +42,7 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
// Validation schema
|
||||
const { handleSubmit, errors, defineField } = useForm<IntegrationEncounterFormData>({
|
||||
const { handleSubmit, errors, defineField, meta } = useForm<IntegrationEncounterFormData>({
|
||||
validationSchema: toTypedSchema(IntegrationEncounterSchema),
|
||||
})
|
||||
|
||||
@@ -154,8 +154,33 @@ const onSubmit = handleSubmit((values) => {
|
||||
const formRef = ref<HTMLFormElement | null>(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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
<Icon
|
||||
name="i-lucide-save"
|
||||
|
||||
Reference in New Issue
Block a user