28 lines
825 B
TypeScript
Raw Normal View History

2021-03-13 02:31:57 -07:00
import SlimSelect from 'slim-select';
2021-03-14 01:06:35 -07:00
import { getElements } from '../util';
2021-03-13 02:31:57 -07:00
export function initStaticSelect(): void {
for (const select of getElements<HTMLSelectElement>('.netbox-static-select')) {
2021-03-13 02:31:57 -07:00
if (select !== null) {
const label = document.querySelector(`label[for="${select.id}"]`) as HTMLLabelElement;
2021-03-14 01:06:35 -07:00
2021-03-13 02:31:57 -07:00
let placeholder;
if (label !== null) {
placeholder = `Select ${label.innerText.trim()}`;
}
2021-03-14 01:06:35 -07:00
const instance = new SlimSelect({
2021-03-13 02:31:57 -07:00
select,
allowDeselect: true,
deselectLabel: `<i class="mdi mdi-close-circle"></i>`,
2021-03-13 02:31:57 -07:00
placeholder,
});
2021-03-14 01:06:35 -07:00
// Don't copy classes from select element to SlimSelect instance.
for (const className of select.classList) {
instance.slim.container.classList.remove(className);
}
2021-03-13 02:31:57 -07:00
}
}
}