From b6fbc3f44102723b181e569e04887103fd1ecff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C2=ABMalo=C2=BB=20Skrylev?= Date: Thu, 20 May 2021 23:29:54 +0300 Subject: [PATCH] feat: optionParent Select.js custom element + optionParent Select.js custom element feature, allowing to explicitly reassign parent for select's options, required for the novel React. --- js/select.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/select.js b/js/select.js index 63f7d8303c..a904681da4 100644 --- a/js/select.js +++ b/js/select.js @@ -30,8 +30,10 @@ /** * Options for the select * @member FormSelect#options + * @prop {Element} optionParent [optionParent=] - Parent element to scan option and optgroup elements from, + * default is the select element itself (optional) */ - this.options = $.extend({}, FormSelect.defaults, options); + this.options = $.extend({ optionParent: this.$el }, FormSelect.defaults, options); this.isMultiple = this.$el.prop('multiple'); @@ -182,7 +184,7 @@ } // Create dropdown - this.$selectOptions = this.$el.children('option, optgroup'); + this.$selectOptions = $(this.options.optionParent).children('option, optgroup'); this.dropdownOptions = document.createElement('ul'); this.dropdownOptions.id = `select-options-${M.guid()}`; $(this.dropdownOptions).addClass( @@ -214,6 +216,10 @@ this._addOptionToValueDict(el, optionEl); }); } + + if (this.options.optionParent != this.$el[0]) { + this.el.appendChild(el); + } }); }