Skip to content

Commit 0d61dcb

Browse files
committed
Fixes #7034: Update VLAN Scope parent selectors and run change handler on load
1 parent 2fb1d38 commit 0d61dcb

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

netbox/project-static/src/forms/scopeSelector.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getElements } from '../util';
1+
import { getElements, toggleVisibility } from '../util';
22

33
type ShowHideMap = {
44
default: { hide: string[]; show: string[] };
@@ -62,19 +62,21 @@ const showHideMap: ShowHideMap = {
6262
*/
6363
function toggleParentVisibility(query: string, action: 'show' | 'hide') {
6464
for (const element of getElements(query)) {
65-
if (action === 'show') {
66-
element.parentElement?.classList.remove('d-none', 'invisible');
67-
} else {
68-
element.parentElement?.classList.add('d-none', 'invisible');
65+
const parent = element.parentElement?.parentElement as Nullable<HTMLDivElement>;
66+
if (parent !== null) {
67+
if (action === 'show') {
68+
toggleVisibility(parent, 'show');
69+
} else {
70+
toggleVisibility(parent, 'hide');
71+
}
6972
}
7073
}
7174
}
7275

7376
/**
7477
* Handle changes to the Scope Type field.
7578
*/
76-
function handleScopeChange(event: Event) {
77-
const element = event.currentTarget as HTMLSelectElement;
79+
function handleScopeChange(element: HTMLSelectElement) {
7880
// Scope type's innerText looks something like `DCIM > region`.
7981
const scopeType = element.options[element.selectedIndex].innerText.toLowerCase();
8082

@@ -104,6 +106,7 @@ function handleScopeChange(event: Event) {
104106
*/
105107
export function initScopeSelector(): void {
106108
for (const element of getElements<HTMLSelectElement>('#id_scope_type')) {
107-
element.addEventListener('change', handleScopeChange);
109+
handleScopeChange(element);
110+
element.addEventListener('change', () => handleScopeChange(element));
108111
}
109112
}

0 commit comments

Comments
 (0)