From 6c5dd3a4f9b579a79c35e359beb2be22ddd2c642 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Wed, 12 Oct 2022 15:48:22 +0530 Subject: [PATCH] fix: prevent Create from appearing as Link value --- src/components/Controls/AutoComplete.vue | 19 ++++++++----------- src/components/Controls/Link.vue | 7 ++----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/components/Controls/AutoComplete.vue b/src/components/Controls/AutoComplete.vue index 80b31c68..a30b3dbf 100644 --- a/src/components/Controls/AutoComplete.vue +++ b/src/components/Controls/AutoComplete.vue @@ -82,7 +82,7 @@ export default { value: { immediate: true, handler(newValue) { - this.linkValue = this.getLabel(newValue); + this.linkValue = this.getLinkValue(newValue); }, }, }, @@ -90,7 +90,7 @@ export default { doc: { default: null }, }, mounted() { - this.linkValue = this.getLabel(this.linkValue || this.value); + this.linkValue = this.getLinkValue(this.linkValue || this.value); }, computed: { options() { @@ -102,7 +102,7 @@ export default { }, }, methods: { - getLabel(value) { + getLinkValue(value) { const oldValue = this.linkValue; let option = this.options.find((o) => o.value === value); if (option === undefined) { @@ -111,14 +111,6 @@ export default { return option?.label ?? oldValue; }, - getValue(label) { - let option = this.options.find((o) => o.label === label); - if (option === undefined) { - option = this.options.find((o) => o.value === label); - } - - return option?.value ?? label; - }, async updateSuggestions(keyword) { if (typeof keyword === 'string') { this.linkValue = keyword; @@ -156,6 +148,11 @@ export default { .map(({ item }) => item); }, setSuggestion(suggestion) { + if (suggestion?.actionOnly) { + this.linkValue = this.value; + return; + } + if (suggestion) { this.linkValue = suggestion.label; this.triggerChange(suggestion.value); diff --git a/src/components/Controls/Link.vue b/src/components/Controls/Link.vue index 0f632ff8..6dcdbdb5 100644 --- a/src/components/Controls/Link.vue +++ b/src/components/Controls/Link.vue @@ -17,10 +17,6 @@ export default { if (this.value) { this.linkValue = this.value; } - - if (this.df.fieldname === 'incomeAccount') { - window.l = this; - } }, watch: { value: { @@ -89,6 +85,7 @@ export default { '{{ t`No results found` }}', }), action: () => {}, + actionOnly: true, }, ]; } @@ -98,8 +95,8 @@ export default { getCreateNewOption() { return { label: t`Create`, - value: 'Create', action: () => this.openNewDoc(), + actionOnly: true, component: markRaw({ template: '
{{ t`Create` }}' +