mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 00:58:16 -06:00
16293 fix form data handler deleting checkbox data
In NetBox, formData may have multiple values associated with a given key (see netbox/templates/django/forms/widgets/checkbox.html). So instead of a for loop over all formData.entries(), retrieve all values using formData.getAll(), delete all keys from formData, then append all non-empty values back in.
This commit is contained in:
parent
8e48e939aa
commit
3ec84e36d5
@ -42,9 +42,15 @@ function initWindow(): void {
|
||||
if (documentForm.method.toUpperCase() == 'GET') {
|
||||
documentForm.addEventListener('formdata', function (event: FormDataEvent) {
|
||||
const formData: FormData = event.formData;
|
||||
for (const [name, value] of Array.from(formData.entries())) {
|
||||
if (value === '') formData.delete(name);
|
||||
}
|
||||
// formData may have multiple values associated with a given key
|
||||
// (see netbox/templates/django/forms/widgets/checkbox.html).
|
||||
for (const name of Array.from(new Set(formData.keys()))) {
|
||||
const values = formData.getAll(name);
|
||||
formData.delete(name);
|
||||
values.forEach(value => {
|
||||
if (value !== '') formData.append(name, value)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user