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
|
|
|
|
2021-08-23 22:31:36 -07:00
|
|
|
export function initStaticSelect(): void {
|
2021-07-17 21:51:47 -07:00
|
|
|
for (const select of getElements<HTMLSelectElement>('.netbox-static-select')) {
|
2021-03-13 02:31:57 -07:00
|
|
|
if (select !== null) {
|
2021-08-30 17:48:33 -07:00
|
|
|
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,
|
2021-04-22 15:58:46 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|