diff --git a/frontend/src/components/widget/deWidget/DeSelect.vue b/frontend/src/components/widget/deWidget/DeSelect.vue index a0f2b5a393..7038e8938b 100644 --- a/frontend/src/components/widget/deWidget/DeSelect.vue +++ b/frontend/src/components/widget/deWidget/DeSelect.vue @@ -157,6 +157,7 @@ export default { this.element.options.attrs.fieldId.length > 0 && method(param).then(res => { this.data = this.optionData(res.data) + this.clearDefault(this.data) bus.$emit('valid-values-change', true) }).catch(e => { bus.$emit('valid-values-change', false) @@ -228,6 +229,27 @@ export default { bus.$off('reset-default-value', this.resetDefaultValue) }, methods: { + clearDefault(optionList) { + const emptyOption = !optionList?.length + + if (!this.inDraw && this.element.options.value) { + if (Array.isArray(this.element.options.value)) { + if (emptyOption) { + this.element.options.value = [] + return + } + const tempValueArray = JSON.parse(JSON.stringify(this.element.options.value)) + this.element.options.value = tempValueArray.filter(item => optionList.some(option => option === item)) + } else { + if (emptyOption) { + this.element.options.value = '' + return + } + const tempValueArray = JSON.parse(JSON.stringify(this.element.options.value.split(','))) + this.element.options.value = tempValueArray.filter(item => optionList.some(option => option === item)).join(',') + } + } + }, clearHandler() { this.value = this.element.options.attrs.multiple ? [] : null this.$refs.deSelect && this.$refs.deSelect.resetSelectAll && this.$refs.deSelect.resetSelectAll() diff --git a/frontend/src/components/widget/deWidget/DeSelectGrid.vue b/frontend/src/components/widget/deWidget/DeSelectGrid.vue index b6cb323382..d4887feb9a 100644 --- a/frontend/src/components/widget/deWidget/DeSelectGrid.vue +++ b/frontend/src/components/widget/deWidget/DeSelectGrid.vue @@ -179,6 +179,7 @@ export default { this.element.options.attrs.fieldId.length > 0 && method(param).then(res => { this.data = this.optionData(res.data) + this.clearDefault(this.data) this.changeInputStyle() if (this.element.options.attrs.multiple) { this.checkAll = this.value.length === this.data.length @@ -250,6 +251,27 @@ export default { bus.$off('reset-default-value', this.resetDefaultValue) }, methods: { + clearDefault(optionList) { + const emptyOption = !optionList?.length + + if (!this.inDraw && this.element.options.value) { + if (Array.isArray(this.element.options.value)) { + if (emptyOption) { + this.element.options.value = [] + return + } + const tempValueArray = JSON.parse(JSON.stringify(this.element.options.value)) + this.element.options.value = tempValueArray.filter(item => optionList.some(option => option === item)) + } else { + if (emptyOption) { + this.element.options.value = '' + return + } + const tempValueArray = JSON.parse(JSON.stringify(this.element.options.value.split(','))) + this.element.options.value = tempValueArray.filter(item => optionList.some(option => option === item)).join(',') + } + } + }, clearHandler() { this.value = this.element.options.attrs.multiple ? [] : null this.checkAll = false