mirror of
https://github.com/infinition/Bjorn.git
synced 2025-12-06 06:11:46 +00:00
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:
4
utils.py
4
utils.py
@@ -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():
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user