Merge pull request #49 from afreeland/afreeland/fix-web-save-for-arrays

Fixes an issue with array based fields when saving from the web UI
This commit is contained in:
infinition
2024-11-19 15:23:49 +01:00
committed by GitHub
2 changed files with 16 additions and 3 deletions

View File

@@ -728,6 +728,10 @@ method=auto
elif isinstance(value, (int, float)):
current_config[key] = value
elif isinstance(value, list):
# Lets boot any values in a list that are just empty strings
for val in value[:]:
if val == "" :
value.remove(val)
current_config[key] = value
elif isinstance(value, str):
if value.replace('.', '', 1).isdigit():

View File

@@ -68,12 +68,21 @@ function generateConfigForm(config) {
const formData = new FormData(formElement);
const formDataObj = {};
// Each of these fields contains an array of data. Lets track these so we can ensure the format remains an array for the underlying structure.
const arrayFields = [
"portlist",
"mac_scan_blacklist",
"ip_scan_blacklist",
"steal_file_names",
"steal_file_extensions",
];
formData.forEach((value, key) => {
if (value.includes(',')) {
// Check if the input from the user contains a `,` character or is a known array field
if (value.includes(',') || arrayFields.includes(key)) {
formDataObj[key] = value.split(',').map(item => {
const trimmedItem = item.trim();
return isNaN(trimmedItem) ? trimmedItem : parseFloat(trimmedItem);
return isNaN(trimmedItem) || trimmedItem == "" ? trimmedItem : parseFloat(trimmedItem);
});
} else {
formDataObj[key] = value === 'on' ? true : (isNaN(value) ? value : parseFloat(value));