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() {
|
2021-03-14 01:06:35 -07:00
|
|
|
for (const select of getElements<HTMLSelectElement>('.netbox-select2-static')) {
|
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="bi bi-x-circle"></i>`,
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|