From b12849abde80c6029931cf809f43b60f834d2129 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 10 Sep 2024 11:14:20 -0300 Subject: [PATCH] Fixes to value update logic in text-based metadata inputs. --- .../components/metadata-types/text/TainacanText.vue | 11 +++++++---- .../metadata-types/textarea/TainacanTextarea.vue | 11 ++++++++++- .../components/metadata-types/url/TainacanUrl.vue | 13 +++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/views/admin/components/metadata-types/text/TainacanText.vue b/src/views/admin/components/metadata-types/text/TainacanText.vue index e1aa123f4..d3f71dcee 100644 --- a/src/views/admin/components/metadata-types/text/TainacanText.vue +++ b/src/views/admin/components/metadata-types/text/TainacanText.vue @@ -8,7 +8,7 @@ v-imask="getMask" class="input" :disabled="disabled" - :value="value" + :value="localValue" :placeholder="itemMetadatum.metadatum.placeholder ? itemMetadatum.metadatum.placeholder : ''" :maxlength="getMaxlength" @focus="onMobileSpecialFocus" @@ -16,17 +16,17 @@ @input="($event) => getMask ? null : onInput($event.target.value)" @blur="onBlur"> - {{ value.length }} / {{ getMaxlength }} + {{ localValue.length }} / {{ getMaxlength }} @@ -11,7 +11,7 @@ v-if="itemMetadatum.item.id" class="add-new-term"> @@ -39,15 +39,20 @@ export default { emits: [ 'update:value', 'blur' ], data() { return { + localValue: '', isPreviewingHtml: false, singleHTMLPreview: '' } }, + created() { + this.localValue = this.value ? JSON.parse(JSON.stringify(this.value)) : ''; + }, methods: { onInput(value) { this.isPreviewingHtml = false; this.singleHTMLPreview = ''; + this.localValue = value; this.changeValue(value); }, changeValue: _.debounce(function(value) { @@ -63,7 +68,7 @@ export default { }, previewHtml() { // If we are going to display preview, renders it - if (!this.isPreviewingHtml) { + if ( !this.isPreviewingHtml ) { // Multivalued metadata need to be split as the values_as_html shows every value if (this.itemMetadatum.metadatum.multiple == 'yes') { @@ -71,7 +76,7 @@ export default { const valuesAsHtml = this.createElementFromHTML(this.itemMetadatum.value_as_html); const valuesAsArray = Object.values(valuesAsHtml.children).filter((aValue) => aValue.outerHTML != ' | '); - const singleValueIndex = this.itemMetadatum.value.findIndex((aValue) => aValue == this.value); + const singleValueIndex = this.itemMetadatum.value.findIndex((aValue) => aValue == this.localValue); if (singleValueIndex >= 0) this.singleHTMLPreview = valuesAsArray[singleValueIndex].outerHTML;