Skip to content

Fixes #7034: Update VLAN Scope parent selectors and run change handler on load #7050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/version-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [#6982](https://github.com/netbox-community/netbox/issues/6982) - Fix styling of empty dropdown list under dark mode
* [#6996](https://github.com/netbox-community/netbox/issues/6996) - Global search bar should be full width on mobile
* [#7001](https://github.com/netbox-community/netbox/issues/7001) - Fix page focus on load
* [#7034](https://github.com/netbox-community/netbox/issues/7034) - Fix toggling of VLAN group scope selector fields

---

Expand Down
14 changes: 7 additions & 7 deletions netbox/project-static/dist/netbox.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions netbox/project-static/dist/netbox.js.map

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions netbox/project-static/src/forms/scopeSelector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getElements } from '../util';
import { getElements, toggleVisibility } from '../util';

type ShowHideMap = {
default: { hide: string[]; show: string[] };
Expand Down Expand Up @@ -62,19 +62,21 @@ const showHideMap: ShowHideMap = {
*/
function toggleParentVisibility(query: string, action: 'show' | 'hide') {
for (const element of getElements(query)) {
if (action === 'show') {
element.parentElement?.classList.remove('d-none', 'invisible');
} else {
element.parentElement?.classList.add('d-none', 'invisible');
const parent = element.parentElement?.parentElement as Nullable<HTMLDivElement>;
if (parent !== null) {
if (action === 'show') {
toggleVisibility(parent, 'show');
} else {
toggleVisibility(parent, 'hide');
}
}
}
}

/**
* Handle changes to the Scope Type field.
*/
function handleScopeChange(event: Event) {
const element = event.currentTarget as HTMLSelectElement;
function handleScopeChange(element: HTMLSelectElement) {
// Scope type's innerText looks something like `DCIM > region`.
const scopeType = element.options[element.selectedIndex].innerText.toLowerCase();

Expand Down Expand Up @@ -104,6 +106,7 @@ function handleScopeChange(event: Event) {
*/
export function initScopeSelector(): void {
for (const element of getElements<HTMLSelectElement>('#id_scope_type')) {
element.addEventListener('change', handleScopeChange);
handleScopeChange(element);
element.addEventListener('change', () => handleScopeChange(element));
}
}