diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index c4d9a4149..1fec1e6c9 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -13,13 +13,12 @@ import VnConfirm from './ui/VnConfirm.vue'; import { tMobile } from 'src/composables/tMobile'; import { useArrayData } from 'src/composables/useArrayData'; import { getDifferences, getUpdatedValues } from 'src/filters'; - const { push } = useRouter(); const quasar = useQuasar(); const state = useState(); const stateStore = useStateStore(); const { t } = useI18n(); -const { validate } = useValidator(); +const { validate, validations } = useValidator(); const { notify } = useNotify(); const route = useRoute(); const myForm = ref(null); @@ -119,7 +118,7 @@ const defaultButtons = computed(() => ({ color: 'primary', icon: 'save', label: 'globals.save', - click: async () => await save(), + click: async (evt) => submitForm(evt), type: 'submit', }, reset: { @@ -132,6 +131,13 @@ const defaultButtons = computed(() => ({ ...$props.defaultButtons, })); +const submitForm = async (evt) => { + const isFormValid = await myForm.value.validate(); + if (isFormValid) { + await save(evt); + } +}; + onMounted(async () => { nextTick(() => (componentIsRendered.value = true)); @@ -227,10 +233,9 @@ async function save() { const method = $props.urlCreate ? 'post' : 'patch'; const url = $props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url; - let response; - - if ($props.saveFn) response = await $props.saveFn(body); - else response = await axios[method](url, body); + const response = await Promise.resolve( + $props.saveFn ? $props.saveFn(body) : axios[method](url, body), + ); if ($props.urlCreate) notify('globals.dataCreated', 'positive'); @@ -307,11 +312,13 @@ async function onKeyup(evt) { selectionStart = selectionEnd = selectionStart + 1; return; } - await save(); + await myForm.value.submit(evt); } } defineExpose({ + submitForm, + myForm, save, isLoading, hasChanges, @@ -325,7 +332,7 @@ defineExpose({ diff --git a/src/components/FormModelPopup.vue b/src/components/FormModelPopup.vue index 85943e91e..34aec96d8 100644 --- a/src/components/FormModelPopup.vue +++ b/src/components/FormModelPopup.vue @@ -41,9 +41,12 @@ const onDataSaved = async (formData, requestResponse) => { emit('onDataSaved', formData, requestResponse); }; -const onClick = async (saveAndContinue) => { +const onClick = async (saveAndContinue = showSaveAndContinueBtn) => { + await formModelRef.value.myForm.validate(true); isSaveAndContinue.value = saveAndContinue; - await formModelRef.value.save(); + if (formModelRef.value) { + await formModelRef.value.submitForm(); + } }; defineExpose({ @@ -59,16 +62,23 @@ defineExpose({ ref="formModelRef" :observe-form-changes="false" :default-actions="false" + @submit="onClick" v-bind="$attrs" @on-data-saved="onDataSaved" + :prevent-submit="false" > - + {{ title }} {{ subtitle }} - + diff --git a/src/components/VnTable/VnTable.vue b/src/components/VnTable/VnTable.vue index b21a622ca..b8494a875 100644 --- a/src/components/VnTable/VnTable.vue +++ b/src/components/VnTable/VnTable.vue @@ -1044,7 +1044,7 @@ const rowCtrlClickFunction = computed(() => { :model="$attrs['data-key'] + 'Create'" @on-data-saved="(_, res) => createForm.onDataSaved(res)" > - + { :key="column.name" :name="`column-create-${column.name}`" :data="data" + :validations="validations" :column-name="column.name" :label="column.label" > diff --git a/src/pages/Customer/Card/CustomerFiscalData.vue b/src/pages/Customer/Card/CustomerFiscalData.vue index 93909eb9c..baa728868 100644 --- a/src/pages/Customer/Card/CustomerFiscalData.vue +++ b/src/pages/Customer/Card/CustomerFiscalData.vue @@ -79,7 +79,7 @@ async function acceptPropagate({ isEqualizated }) { observe-form-changes @on-data-saved="checkEtChanges" > - + diff --git a/src/pages/Entry/Card/EntryBuys.vue b/src/pages/Entry/Card/EntryBuys.vue index dedc9fc85..baa4d96b7 100644 --- a/src/pages/Entry/Card/EntryBuys.vue +++ b/src/pages/Entry/Card/EntryBuys.vue @@ -787,7 +787,7 @@ onMounted(() => { {{ footer?.amount }} / {{ footer?.checkedAmount }} - + { await setBuyUltimate(value, data); } " - :required="true" + required + :rules="[(val) => validations.required(true, val)]" data-cy="itemFk-create-popup" sort-by="nickname DESC" > diff --git a/test/cypress/integration/item/itemSummary.spec.js b/test/cypress/integration/item/itemSummary.spec.js index ad8267ecf..8d67c8e3c 100644 --- a/test/cypress/integration/item/itemSummary.spec.js +++ b/test/cypress/integration/item/itemSummary.spec.js @@ -19,6 +19,7 @@ describe('Item summary', () => { cy.get('.q-menu > .q-list > :nth-child(1) > .q-item__section').click(); cy.dataCy('regularizeStockInput').type('10'); cy.dataCy('Warehouse_select').type('Warehouse One{enter}'); + cy.dataCy('FormModelPopup_save').click(); cy.checkNotification('Data created'); }); });
{{ subtitle }}