Skip to content

Commit

Permalink
[5.x] Avoid creation of duplicate terms in typeahead input (#11060)
Browse files Browse the repository at this point in the history
  • Loading branch information
daun authored Nov 21, 2024
1 parent 5a659c1 commit b02a86d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion resources/js/components/inputs/relationship/SelectField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 };
},
}
}
Expand Down

0 comments on commit b02a86d

Please sign in to comment.