mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 04:56:29 -06:00
#6372: Fix bulk form action form handling
This commit is contained in:
parent
29e41e8e2b
commit
cdc9753009
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -1,10 +1,37 @@
|
|||||||
import { getElements, scrollTo } from './util';
|
import { getElements, scrollTo, findFirstAdjacent, isTruthy } from './util';
|
||||||
|
|
||||||
type ShowHideMap = {
|
type ShowHideMap = {
|
||||||
default: { hide: string[]; show: string[] };
|
default: { hide: string[]; show: string[] };
|
||||||
[k: string]: { hide: string[]; show: string[] };
|
[k: string]: { hide: string[]; show: string[] };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle bulk add/edit/rename form actions.
|
||||||
|
*
|
||||||
|
* @param event Click Event
|
||||||
|
*/
|
||||||
|
function handleFormActionClick(event: Event): void {
|
||||||
|
event.preventDefault();
|
||||||
|
const element = event.currentTarget as HTMLElement;
|
||||||
|
if (element !== null) {
|
||||||
|
const form = findFirstAdjacent<HTMLFormElement>(element, 'form');
|
||||||
|
const href = element.getAttribute('href');
|
||||||
|
if (form !== null && isTruthy(href)) {
|
||||||
|
form.setAttribute('action', href);
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize bulk form action links.
|
||||||
|
*/
|
||||||
|
function initFormActions() {
|
||||||
|
for (const element of getElements<HTMLAnchorElement>('a.formaction')) {
|
||||||
|
element.addEventListener('click', handleFormActionClick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get form data from a form element and transform it into a body usable by fetch.
|
* Get form data from a form element and transform it into a body usable by fetch.
|
||||||
*
|
*
|
||||||
@ -264,7 +291,13 @@ function initScopeSelector() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initForms() {
|
export function initForms() {
|
||||||
for (const func of [initFormElements, initMoveButtons, initSpeedSelector, initScopeSelector]) {
|
for (const func of [
|
||||||
|
initFormElements,
|
||||||
|
initFormActions,
|
||||||
|
initMoveButtons,
|
||||||
|
initSpeedSelector,
|
||||||
|
initScopeSelector,
|
||||||
|
]) {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user