1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add optional selector to getSelectedOptions for more specific field selection

This commit is contained in:
thatmattlove
2022-02-07 14:34:35 -07:00
parent 094d2e586a
commit 7252f0b490

View File

@ -231,11 +231,15 @@ export function scrollTo(element: Element, offset: number = 0): void {
* Iterate through a select element's options and return an array of options that are selected.
*
* @param base Select element.
* @param selector Optionally specify a selector. 'select' by default.
* @returns Array of selected options.
*/
export function getSelectedOptions<E extends HTMLElement>(base: E): SelectedOption[] {
export function getSelectedOptions<E extends HTMLElement>(
base: E,
selector: string = 'select',
): SelectedOption[] {
let selected = [] as SelectedOption[];
for (const element of base.querySelectorAll<HTMLSelectElement>('select')) {
for (const element of base.querySelectorAll<HTMLSelectElement>(selector)) {
if (element !== null) {
const select = { name: element.name, options: [] } as SelectedOption;
for (const option of element.options) {