From 255df3acd647bf56b33946b54ec8e13980f6228b Mon Sep 17 00:00:00 2001
From: Javier Segarra <jsegarra@verdnatura.es>
Date: Fri, 7 Mar 2025 13:33:53 +0100
Subject: [PATCH] fix: refs #8725 streamline form submission logic in
 FormModel.vue

---
 src/components/FormModel.vue      | 18 +++++++-----------
 src/components/FormModelPopup.vue |  5 ++++-
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue
index 57456ba3d..f8e16be53 100644
--- a/src/components/FormModel.vue
+++ b/src/components/FormModel.vue
@@ -128,9 +128,7 @@ const defaultButtons = computed(() => ({
         color: 'primary',
         icon: 'save',
         label: 'globals.save',
-        click: async () => {
-            submitForm();
-        },
+        click: async (evt) => submitForm(evt),
         type: 'submit',
     },
     reset: {
@@ -143,14 +141,10 @@ const defaultButtons = computed(() => ({
     ...$props.defaultButtons,
 }));
 
-const submitForm = async () => {
+const submitForm = async (evt) => {
     const isFormValid = await myForm.value.validate();
     if (isFormValid) {
-        try {
-            await save();
-        } catch (error) {
-            app.config.errorHandler(error);
-        }
+        await save(evt);
     }
 };
 
@@ -328,11 +322,13 @@ async function onKeyup(evt) {
             selectionStart = selectionEnd = selectionStart + 1;
             return;
         }
-        await save();
+        await submitForm();
     }
 }
 
 defineExpose({
+    submitForm,
+    myForm,
     save,
     isLoading,
     hasChanges,
@@ -347,7 +343,7 @@ defineExpose({
             ref="myForm"
             v-if="formData"
             @submit.prevent
-            @keyup.prevent="onKeyup"
+            @keyup="onKeyup"
             @reset="reset"
             class="q-pa-md"
             :style="maxWidth ? 'max-width: ' + maxWidth : ''"
diff --git a/src/components/FormModelPopup.vue b/src/components/FormModelPopup.vue
index b3370e2d1..48a3e77b6 100644
--- a/src/components/FormModelPopup.vue
+++ b/src/components/FormModelPopup.vue
@@ -43,6 +43,9 @@ const onDataSaved = async (formData, requestResponse) => {
 
 const onClick = async (saveAndContinue) => {
     isSaveAndContinue.value = saveAndContinue;
+    if (formModelRef.value) {
+        await formModelRef.value.submitForm();
+    }
 };
 
 defineExpose({
@@ -58,6 +61,7 @@ defineExpose({
         ref="formModelRef"
         :observe-form-changes="false"
         :default-actions="false"
+        @submit="onClick"
         v-bind="$attrs"
         @on-data-saved="onDataSaved"
         @submit.prevent
@@ -87,7 +91,6 @@ defineExpose({
                     :flat="showSaveAndContinueBtn"
                     :label="t('globals.save')"
                     :title="t('globals.save')"
-                    @click="onClick(false)"
                     type="submit"
                     color="primary"
                     class="q-ml-sm"