2
0
mirror of https://github.com/frappe/books.git synced 2025-01-10 18:24:40 +00:00

fix: prevent Create from appearing as Link value

This commit is contained in:
18alantom 2022-10-12 15:48:22 +05:30
parent 110dee04eb
commit 6c5dd3a4f9
2 changed files with 10 additions and 16 deletions

View File

@ -82,7 +82,7 @@ export default {
value: { value: {
immediate: true, immediate: true,
handler(newValue) { handler(newValue) {
this.linkValue = this.getLabel(newValue); this.linkValue = this.getLinkValue(newValue);
}, },
}, },
}, },
@ -90,7 +90,7 @@ export default {
doc: { default: null }, doc: { default: null },
}, },
mounted() { mounted() {
this.linkValue = this.getLabel(this.linkValue || this.value); this.linkValue = this.getLinkValue(this.linkValue || this.value);
}, },
computed: { computed: {
options() { options() {
@ -102,7 +102,7 @@ export default {
}, },
}, },
methods: { methods: {
getLabel(value) { getLinkValue(value) {
const oldValue = this.linkValue; const oldValue = this.linkValue;
let option = this.options.find((o) => o.value === value); let option = this.options.find((o) => o.value === value);
if (option === undefined) { if (option === undefined) {
@ -111,14 +111,6 @@ export default {
return option?.label ?? oldValue; 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) { async updateSuggestions(keyword) {
if (typeof keyword === 'string') { if (typeof keyword === 'string') {
this.linkValue = keyword; this.linkValue = keyword;
@ -156,6 +148,11 @@ export default {
.map(({ item }) => item); .map(({ item }) => item);
}, },
setSuggestion(suggestion) { setSuggestion(suggestion) {
if (suggestion?.actionOnly) {
this.linkValue = this.value;
return;
}
if (suggestion) { if (suggestion) {
this.linkValue = suggestion.label; this.linkValue = suggestion.label;
this.triggerChange(suggestion.value); this.triggerChange(suggestion.value);

View File

@ -17,10 +17,6 @@ export default {
if (this.value) { if (this.value) {
this.linkValue = this.value; this.linkValue = this.value;
} }
if (this.df.fieldname === 'incomeAccount') {
window.l = this;
}
}, },
watch: { watch: {
value: { value: {
@ -89,6 +85,7 @@ export default {
'<span class="text-gray-600">{{ t`No results found` }}</span>', '<span class="text-gray-600">{{ t`No results found` }}</span>',
}), }),
action: () => {}, action: () => {},
actionOnly: true,
}, },
]; ];
} }
@ -98,8 +95,8 @@ export default {
getCreateNewOption() { getCreateNewOption() {
return { return {
label: t`Create`, label: t`Create`,
value: 'Create',
action: () => this.openNewDoc(), action: () => this.openNewDoc(),
actionOnly: true,
component: markRaw({ component: markRaw({
template: template:
'<div class="flex items-center font-semibold">{{ t`Create` }}' + '<div class="flex items-center font-semibold">{{ t`Create` }}' +