fix: refs #8725 streamline form submission logic in FormModel.vue

This commit is contained in:
Javier Segarra 2025-03-07 13:33:53 +01:00
parent 32dac089f8
commit 255df3acd6
2 changed files with 11 additions and 12 deletions

View File

@ -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 : ''"

View File

@ -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"