From b02a86d473b5269194ebed0d9fc17a719ad93fe3 Mon Sep 17 00:00:00 2001 From: Philipp Daun Date: Thu, 21 Nov 2024 16:18:25 +0100 Subject: [PATCH] [5.x] Avoid creation of duplicate terms in typeahead input (#11060) --- .../js/components/inputs/relationship/SelectField.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/js/components/inputs/relationship/SelectField.vue b/resources/js/components/inputs/relationship/SelectField.vue index 4d31c01b7c..b4a23931b3 100644 --- a/resources/js/components/inputs/relationship/SelectField.vue +++ b/resources/js/components/inputs/relationship/SelectField.vue @@ -12,7 +12,7 @@ :options="options" :get-option-key="(option) => option.id" :get-option-label="(option) => __(option.title)" - :create-option="(value) => ({ title: value, id: value })" + :create-option="(value) => createOption(value)" :placeholder="__(config.placeholder) || __('Choose...')" :searchable="true" :taggable="isTaggable" @@ -140,6 +140,11 @@ export default { this.$emit('input', items); }, + createOption(value) { + const existing = this.options.find((option) => option.title === value); + return existing || { id: value, title: value }; + }, + } }