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); + } }); }