Choices/src/scripts/src/components/wrapped-select.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

import WrappedElement from './wrapped-element';
import templates from './../templates';
export default class WrappedSelect extends WrappedElement {
constructor(instance, element, classNames) {
super(instance, element, classNames);
this.parentInstance = instance;
this.element = element;
this.classNames = classNames;
}
2017-10-18 14:05:07 +02:00
getElement() {
super.getElement();
}
conceal() {
super.conceal();
}
reveal() {
super.reveal();
}
2017-10-18 09:43:56 +02:00
enable() {
super.enable();
}
disable() {
2017-12-19 14:08:57 +01:00
super.disable();
2017-10-18 09:43:56 +02:00
}
getPlaceholderOption() {
return this.element.querySelector('option[placeholder]');
}
getOptions() {
return Array.from(this.element.options);
}
getOptionGroups() {
return Array.from(this.element.getElementsByTagName('OPTGROUP'));
}
setOptions(options) {
const fragment = document.createDocumentFragment();
const addOptionToFragment = (data) => {
// Create a standard select option
const template = templates.option(data);
// Append it to fragment
fragment.appendChild(template);
};
// Add each list item to list
options.forEach(optionData => addOptionToFragment(optionData));
this.appendDocFragment(fragment);
}
appendDocFragment(fragment) {
this.element.innerHTML = '';
this.element.appendChild(fragment);
}
}