From ee1cc30fb756a01ae86fce1a0c378e80480bdad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Tue, 26 Sep 2023 14:38:33 +0200 Subject: [PATCH] refactorate prerecordedfield initialization & reinit in fast edition mode --- .../Feature/Edit/FeatureExtraForm.vue | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/components/Feature/Edit/FeatureExtraForm.vue b/src/components/Feature/Edit/FeatureExtraForm.vue index b958d7a2..8315eb67 100644 --- a/src/components/Feature/Edit/FeatureExtraForm.vue +++ b/src/components/Feature/Edit/FeatureExtraForm.vue @@ -375,9 +375,15 @@ export default { }, watch: { - 'field.value': function(newValue) { + 'field.value': function(newValue, oldValue) { if (newValue) { this.error = null; + // In fast edition, prerecordedlist is not updated, thus the value stay the same + // in this case we renitialize the field. This doesn't impact usual behavior if user reselect the same option + if (this.field.field_type === 'pre_recorded_list' && + newValue.label && newValue.label === oldValue.label) { + this.initPrerecordedField(); + } } }, @@ -398,22 +404,9 @@ export default { created() { if (this.field) { - const { field_type, options, value } = this.field; + const { field_type, value } = this.field; if (field_type === 'pre_recorded_list') { - this.loadingPrerecordedListValues = true; - this.GET_SELECTED_PRERECORDED_LIST_VALUES({ - name: options[0], - pattern: '' - }) - .then(() => { - this.loadingPrerecordedListValues = false; - }) - .catch(() => { - this.loadingPrerecordedListValues = false; - }); - if (value) { - this.selectedPrerecordedValue = { label: value.label ? value.label : value }; - } + this.initPrerecordedField(); } else if (field_type === 'multi_choices_list' && value) { this.selectedMultipleCheckbox = value; } @@ -436,6 +429,24 @@ export default { 'SET_EXTRA_FORMS', ]), + initPrerecordedField() { + const { options, value } = this.field; + this.loadingPrerecordedListValues = true; + this.GET_SELECTED_PRERECORDED_LIST_VALUES({ + name: options[0], + pattern: '' + }) + .then(() => { + this.loadingPrerecordedListValues = false; + }) + .catch(() => { + this.loadingPrerecordedListValues = false; + }); + if (value) { + this.selectedPrerecordedValue = { label: value.label ? value.label : value }; + } + }, + updateStore_extra_form(evt) { if (this.field) { let newValue; -- GitLab