diff --git a/package.json b/package.json index 71d80d401..1e5ac3bbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-front", - "version": "24.30.1", + "version": "24.30.2", "description": "Salix frontend", "productName": "Salix", "author": "Verdnatura", diff --git a/src/boot/axios.js b/src/boot/axios.js index fa8a08003..9b32275bd 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -43,6 +43,15 @@ const onResponseError = (error) => { } switch (response?.status) { + case 422: + if (error.name == 'ValidationError') + message += + ' "' + + responseError.details.context + + '.' + + Object.keys(responseError.details.codes).join(',') + + '"'; + break; case 500: message = 'errors.statusInternalServerError'; break; diff --git a/src/boot/qformMixin.js b/src/boot/qformMixin.js index 0bf1f9795..fc7852369 100644 --- a/src/boot/qformMixin.js +++ b/src/boot/qformMixin.js @@ -1,28 +1,11 @@ import { getCurrentInstance } from 'vue'; -const filterAvailableInput = (element) => { - return element.classList.contains('q-field__native') && !element.disabled; -}; -const filterAvailableText = (element) => { - return ( - element.__vueParentComponent.type.name === 'QInput' && - element.__vueParentComponent?.attrs?.class !== 'vn-input-date' - ); -}; - export default { mounted: function () { const vm = getCurrentInstance(); if (vm.type.name === 'QForm') { if (!['searchbarForm', 'filterPanelForm'].includes(this.$el?.id)) { - // AUTOFOCUS - const elementsArray = Array.from(this.$el.elements); - const availableInputs = elementsArray.filter(filterAvailableInput); - const firstInputElement = availableInputs.find(filterAvailableText); - - if (firstInputElement) { - firstInputElement.focus(); - } + // TODO: AUTOFOCUS IS NOT FOCUSING const that = this; this.$el.addEventListener('keyup', function (evt) { if (evt.key === 'Enter') { diff --git a/src/components/CreateNewCityForm.vue b/src/components/CreateNewCityForm.vue index 45fa61dff..50dc41b5f 100644 --- a/src/components/CreateNewCityForm.vue +++ b/src/components/CreateNewCityForm.vue @@ -4,8 +4,8 @@ import { useI18n } from 'vue-i18n'; import FetchData from 'components/FetchData.vue'; import VnRow from 'components/ui/VnRow.vue'; -import VnSelect from 'src/components/common/VnSelect.vue'; -import VnInput from 'src/components/common/VnInput.vue'; +import VnSelectProvince from 'components/VnSelectProvince.vue'; +import VnInput from 'components/common/VnInput.vue'; import FormModelPopup from './FormModelPopup.vue'; const emit = defineEmits(['onDataSaved']); @@ -19,8 +19,8 @@ const cityFormData = reactive({ const provincesOptions = ref([]); -const onDataSaved = (dataSaved) => { - emit('onDataSaved', dataSaved); +const onDataSaved = (...args) => { + emit('onDataSaved', ...args); }; @@ -36,7 +36,7 @@ const onDataSaved = (dataSaved) => { :form-initial-data="cityFormData" url-create="towns" model="city" - @on-data-saved="onDataSaved($event)" + @on-data-saved="onDataSaved" > diff --git a/src/components/CreateNewPostcodeForm.vue b/src/components/CreateNewPostcodeForm.vue index 25a61a0ca..a426ac2b4 100644 --- a/src/components/CreateNewPostcodeForm.vue +++ b/src/components/CreateNewPostcodeForm.vue @@ -5,9 +5,9 @@ import { useI18n } from 'vue-i18n'; import FetchData from 'components/FetchData.vue'; import VnRow from 'components/ui/VnRow.vue'; import VnSelect from 'src/components/common/VnSelect.vue'; +import VnSelectProvince from 'src/components/VnSelectProvince.vue'; import VnInput from 'src/components/common/VnInput.vue'; import CreateNewCityForm from './CreateNewCityForm.vue'; -import CreateNewProvinceForm from './CreateNewProvinceForm.vue'; import VnSelectDialog from 'components/common/VnSelectDialog.vue'; import FormModelPopup from './FormModelPopup.vue'; @@ -22,20 +22,17 @@ const postcodeFormData = reactive({ townFk: null, }); -const townsFetchDataRef = ref(null); const provincesFetchDataRef = ref(null); const countriesOptions = ref([]); const provincesOptions = ref([]); -const townsLocationOptions = ref([]); +const town = ref({}); -const onDataSaved = (formData) => { +function onDataSaved(formData) { const newPostcode = { ...formData, }; - const townObject = townsLocationOptions.value.find( - ({ id }) => id === formData.townFk - ); - newPostcode.town = townObject?.name; + newPostcode.town = town.value.name; + newPostcode.townFk = town.value.id; const provinceObject = provincesOptions.value.find( ({ id }) => id === formData.provinceFk ); @@ -43,39 +40,41 @@ const onDataSaved = (formData) => { const countryObject = countriesOptions.value.find( ({ id }) => id === formData.countryFk ); - newPostcode.country = countryObject?.country; + newPostcode.country = countryObject?.name; emit('onDataSaved', newPostcode); -}; +} -const onCityCreated = async ({ name, provinceFk }, formData) => { - await townsFetchDataRef.value.fetch(); - formData.townFk = townsLocationOptions.value.find((town) => town.name === name).id; - formData.provinceFk = provinceFk; - formData.countryFk = provincesOptions.value.find( - (province) => province.id === provinceFk - ).countryFk; -}; - -const onProvinceCreated = async ({ name }, formData) => { +async function onCityCreated(newTown, formData) { await provincesFetchDataRef.value.fetch(); - formData.provinceFk = provincesOptions.value.find( - (province) => province.name === name - ).id; -}; + newTown.province = provincesOptions.value.find( + (province) => province.id === newTown.provinceFk + ); + formData.townFk = newTown; + setTown(newTown, formData); +} + +function setTown(newTown, data) { + if (!newTown) return; + town.value = newTown; + data.provinceFk = newTown.provinceFk; + data.countryFk = newTown.province.countryFk; +} + +async function setProvince(id, data) { + await provincesFetchDataRef.value.fetch(); + const newProvince = provincesOptions.value.find((province) => province.id == id); + if (!newProvince) return; + + data.countryFk = newProvince.countryFk; +}