From 701f1e100f0de4d0a0a5ac4aea68686fdaf0ec66 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 21 Nov 2023 12:50:05 +0100 Subject: [PATCH 1/3] refs #5858 feat: add catch when patch FormModel --- src/components/FormModel.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index e8a9e4c17..f8daea34e 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -80,7 +80,13 @@ async function save() { }); } isLoading.value = true; - await axios.patch($props.urlUpdate || $props.url, formData.value); + try { + await axios.patch($props.urlUpdate || $props.url, formData.value); + } catch (err) { + if (err) { + isLoading.value = false; + } + } originalData.value = JSON.parse(JSON.stringify(formData.value)); hasChanges.value = false; From 333050b6a78b07921ce583266d73bd6704099d64 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 22 Nov 2023 07:12:34 +0100 Subject: [PATCH 2/3] refs #5858 feat: add format validation --- src/composables/useValidator.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/composables/useValidator.js b/src/composables/useValidator.js index bc48332a2..625f20911 100644 --- a/src/composables/useValidator.js +++ b/src/composables/useValidator.js @@ -37,6 +37,15 @@ export function useValidator() { const { t } = useI18n(); const validations = function (validation) { return { + format: (value) =>{ + const {allowNull, with: format, allowBlank} = validation; + const message = t(validation.message) || validation.message; + if(!allowBlank && value ==='') return message + if(!allowNull && value === null) return message + + const isValid = new RegExp(format).test(value) + if(!isValid) return message + }, presence: (value) => { let message = `Value can't be empty`; if (validation.message) From 4ccb11997e51ed17830dcae7349d9db9a03be9d2 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 22 Dec 2023 10:32:57 +0100 Subject: [PATCH 3/3] refs #5878 lint: eslint --- src/composables/useValidator.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/composables/useValidator.js b/src/composables/useValidator.js index 364d11391..5ad96ea1b 100644 --- a/src/composables/useValidator.js +++ b/src/composables/useValidator.js @@ -30,14 +30,14 @@ export function useValidator() { const { t } = useI18n(); const validations = function (validation) { return { - format: (value) =>{ - const {allowNull, with: format, allowBlank} = validation; + format: (value) => { + const { allowNull, with: format, allowBlank } = validation; const message = t(validation.message) || validation.message; - if(!allowBlank && value ==='') return message - if(!allowNull && value === null) return message + if (!allowBlank && value === '') return message; + if (!allowNull && value === null) return message; - const isValid = new RegExp(format).test(value) - if(!isValid) return message + const isValid = new RegExp(format).test(value); + if (!isValid) return message; }, presence: (value) => { let message = `Value can't be empty`;