From e8266ba3ae769be2d323dd5192da87016bdb0079 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 12 Dec 2023 16:45:49 +1100 Subject: [PATCH] Refactor --- .../controllers/tom_select_controller.js | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/app/webpacker/controllers/tom_select_controller.js b/app/webpacker/controllers/tom_select_controller.js index 9cf4401fe6..1022b788d4 100644 --- a/app/webpacker/controllers/tom_select_controller.js +++ b/app/webpacker/controllers/tom_select_controller.js @@ -3,25 +3,18 @@ import TomSelect from "tom-select/dist/esm/tom-select.complete"; export default class extends Controller { static values = { options: Object }; - static defaults = { - maxItems: 1, - maxOptions: null, - plugins: ["dropdown_input"], - allowEmptyOption: true, - closeAfterSelect: true, - onItemAdd: function () { - this.setTextboxValue(""); - }, - }; connect(options = {}) { - if (this.#placeholder()) { - options.allowEmptyOption = false; - options.placeholder = this.#placeholder(); - } - this.control = new TomSelect(this.element, { - ...this.constructor.defaults, + maxItems: 1, + maxOptions: null, + plugins: ["dropdown_input"], + allowEmptyOption: !this.#placeholder(), + closeAfterSelect: true, + placeholder: this.#placeholder(), + onItemAdd: function () { + this.setTextboxValue(""); + }, ...this.optionsValue, ...options, });