Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions js/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
/**
* Options for the select
* @member FormSelect#options
* @prop {Element} optionParent [optionParent=<element>] - 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');

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -214,6 +216,10 @@
this._addOptionToValueDict(el, optionEl);
});
}

if (this.options.optionParent != this.$el[0]) {
this.el.appendChild(el);
}
});
}

Expand Down