Merge pull request '#8725 - submit_form_onClick' (!1564) from 8725_submit_form_onClick into dev
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #1564 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
7e56cb96ef
|
@ -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({
|
|||
<QForm
|
||||
ref="myForm"
|
||||
v-if="formData"
|
||||
@submit.prevent
|
||||
@submit.prevent="save"
|
||||
@keyup.prevent="onKeyup"
|
||||
@reset="reset"
|
||||
class="q-pa-md"
|
||||
|
@ -339,6 +346,7 @@ defineExpose({
|
|||
name="form"
|
||||
:data="formData"
|
||||
:validate="validate"
|
||||
:validations="validations()"
|
||||
:filter="filter"
|
||||
/>
|
||||
<SkeletonForm v-else />
|
||||
|
|
|
@ -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"
|
||||
>
|
||||
<template #form="{ data, validate }">
|
||||
<template #form="{ data, validate, validations }">
|
||||
<span ref="closeButton" class="close-icon" v-close-popup>
|
||||
<QIcon name="close" size="sm" />
|
||||
</span>
|
||||
<h1 class="title">{{ title }}</h1>
|
||||
<p>{{ subtitle }}</p>
|
||||
<slot name="form-inputs" :data="data" :validate="validate" />
|
||||
<slot
|
||||
name="form-inputs"
|
||||
:data="data"
|
||||
:validate="validate"
|
||||
:validations="validations"
|
||||
/>
|
||||
<div class="q-mt-lg row justify-end">
|
||||
<QBtn
|
||||
:label="t('globals.cancel')"
|
||||
|
@ -87,12 +97,13 @@ defineExpose({
|
|||
:flat="showSaveAndContinueBtn"
|
||||
:label="t('globals.save')"
|
||||
:title="t('globals.save')"
|
||||
@click="onClick(false)"
|
||||
:type="!showSaveAndContinueBtn ? 'submit' : 'button'"
|
||||
color="primary"
|
||||
class="q-ml-sm"
|
||||
:disabled="isLoading"
|
||||
:loading="isLoading"
|
||||
data-cy="FormModelPopup_save"
|
||||
@click="showSaveAndContinueBtn ? onClick(false) : null"
|
||||
z-max
|
||||
/>
|
||||
<QBtn
|
||||
|
@ -100,12 +111,13 @@ defineExpose({
|
|||
:label="t('globals.isSaveAndContinue')"
|
||||
:title="t('globals.isSaveAndContinue')"
|
||||
color="primary"
|
||||
:type="showSaveAndContinueBtn ? 'submit' : 'button'"
|
||||
class="q-ml-sm"
|
||||
:disabled="isLoading"
|
||||
:loading="isLoading"
|
||||
data-cy="FormModelPopup_isSaveAndContinue"
|
||||
@click="showSaveAndContinueBtn ? onClick(true) : null"
|
||||
z-max
|
||||
@click="onClick(true)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
@ -1044,7 +1044,7 @@ const rowCtrlClickFunction = computed(() => {
|
|||
:model="$attrs['data-key'] + 'Create'"
|
||||
@on-data-saved="(_, res) => createForm.onDataSaved(res)"
|
||||
>
|
||||
<template #form-inputs="{ data }">
|
||||
<template #form-inputs="{ data, validations }">
|
||||
<slot name="alter-create" :data="data">
|
||||
<div :style="createComplement?.containerStyle">
|
||||
<div
|
||||
|
@ -1062,6 +1062,7 @@ const rowCtrlClickFunction = computed(() => {
|
|||
:key="column.name"
|
||||
:name="`column-create-${column.name}`"
|
||||
:data="data"
|
||||
:validations="validations"
|
||||
:column-name="column.name"
|
||||
:label="column.label"
|
||||
>
|
||||
|
|
|
@ -79,7 +79,7 @@ async function acceptPropagate({ isEqualizated }) {
|
|||
observe-form-changes
|
||||
@on-data-saved="checkEtChanges"
|
||||
>
|
||||
<template #form="{ data, validate }">
|
||||
<template #form="{ data, validate, validations }">
|
||||
<VnRow>
|
||||
<VnInput
|
||||
:label="t('Social name')"
|
||||
|
@ -112,6 +112,7 @@ async function acceptPropagate({ isEqualizated }) {
|
|||
v-model="data.sageTaxTypeFk"
|
||||
data-cy="sageTaxTypeFk"
|
||||
:required="data.isTaxDataChecked"
|
||||
:rules="[(val) => validations.required(data.isTaxDataChecked, val)]"
|
||||
/>
|
||||
<VnSelect
|
||||
:label="t('Sage transaction type')"
|
||||
|
@ -122,6 +123,9 @@ async function acceptPropagate({ isEqualizated }) {
|
|||
data-cy="sageTransactionTypeFk"
|
||||
v-model="data.sageTransactionTypeFk"
|
||||
:required="data.isTaxDataChecked"
|
||||
:rules="[
|
||||
(val) => validations.required(data.sageTransactionTypeFk, val),
|
||||
]"
|
||||
>
|
||||
<template #option="scope">
|
||||
<QItem v-bind="scope.itemProps">
|
||||
|
|
|
@ -787,7 +787,7 @@ onMounted(() => {
|
|||
<span data-cy="footer-amount">{{ footer?.amount }} / </span>
|
||||
<span style="color: var(--q-positive)">{{ footer?.checkedAmount }}</span>
|
||||
</template>
|
||||
<template #column-create-itemFk="{ data }">
|
||||
<template #column-create-itemFk="{ data, validations }">
|
||||
<VnSelect
|
||||
url="Items/search"
|
||||
v-model="data.itemFk"
|
||||
|
@ -801,7 +801,8 @@ onMounted(() => {
|
|||
await setBuyUltimate(value, data);
|
||||
}
|
||||
"
|
||||
:required="true"
|
||||
required
|
||||
:rules="[(val) => validations.required(true, val)]"
|
||||
data-cy="itemFk-create-popup"
|
||||
sort-by="nickname DESC"
|
||||
>
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue