1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 22:13:53 +01:00

bugfixes / sporadic e logging

This commit is contained in:
Marek Farkaš
2025-02-09 17:46:12 +01:00
parent b4928bcff8
commit ceb6e1bd11
14 changed files with 211 additions and 86 deletions

View File

@@ -42,12 +42,28 @@ function populateFields(data, prefix = "") {
value = ""; // Convert null to an empty string
}
const id = `${prefix}${prefix ? "-" : ""}${key}`;
let id = `${prefix}${prefix ? "-" : ""}${key}`;
const $element = $(`#${id}`);
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
populateFields(value, id);
return;
if (typeof value === "object" && value !== null) {
if (Array.isArray(value)) {
// Handle arrays correctly
value.forEach((item, index) => {
const arrayId = `${id}-${index + 1}`;
const $arrayElement = $(`#${arrayId}`);
if ($arrayElement.length) {
$arrayElement.val(item);
} else {
console.log(`Element with id ${arrayId} not found`);
}
});
return;
} else {
// Handle nested objects
populateFields(value, id);
return;
}
}
if (!$element.length) {
@@ -64,16 +80,6 @@ function populateFields(data, prefix = "") {
} else {
$element.val(value);
}
if (key === "plugins" && Array.isArray(value)) {
const $options = $element.find('option');
$options.each(function() {
const dataName = $(this).data('name');
if (value.includes(dataName)) {
$(this).prop('selected', true);
}
});
}
});
}