fix: checkbox data content
This commit is contained in:
parent
79a7f92ff9
commit
9155b79ec9
3 changed files with 72 additions and 5 deletions
|
@ -100,7 +100,25 @@ const _bp_api = {
|
|||
|
||||
apiCode += `async function _bp_serverAction_${elementId}(e) {
|
||||
const data = {};
|
||||
${params.map(param => ` data.${param} = ${param} ? ${param}.value : null;`).join('\n')}
|
||||
${params.map(param => ` const ${param}_element = document.getElementById('${param}');
|
||||
if (${param}_element) {
|
||||
console.log('Found element: ${param}', ${param}_element);
|
||||
if (${param}_element.type === 'checkbox') {
|
||||
data.${param} = ${param}_element.checked;
|
||||
console.log('Checkbox ${param} value:', ${param}_element.checked);
|
||||
} else if (${param}_element.type === 'radio') {
|
||||
data.${param} = ${param}_element.checked;
|
||||
} else if (${param}_element.value !== undefined) {
|
||||
data.${param} = ${param}_element.value;
|
||||
} else {
|
||||
data.${param} = ${param}_element.textContent;
|
||||
}
|
||||
} else {
|
||||
console.error('[Blueprint] Element with ID ${param} not found');
|
||||
data.${param} = null;
|
||||
}`).join('\n')}
|
||||
|
||||
console.log('Submitting data:', data);
|
||||
|
||||
try {
|
||||
const result = await _bp_api.post('${endpoint}', data);
|
||||
|
@ -114,7 +132,11 @@ ${params.map(param => ` data.${param} = ${param} ? ${param}.value : null;`).joi
|
|||
else {
|
||||
const element = document.getElementById(key);
|
||||
if (element) {
|
||||
element.textContent = result[key];
|
||||
if (element.tagName.toLowerCase() === 'input') {
|
||||
element.value = result[key];
|
||||
} else {
|
||||
element.textContent = result[key];
|
||||
}
|
||||
console.log(\`[Blueprint API] Updated element #\${key} with value: \${result[key]}\`);
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +186,12 @@ function createBlueprintApiServer(port = 3001) {
|
|||
serverCode += `
|
||||
app.post('${endpoint}', async (req, res) => {
|
||||
try {
|
||||
${params.map(param => `const ${param} = req.body.${param};`).join('\n ')}
|
||||
${params.map(param => {
|
||||
return `const ${param} = req.body.${param} !== undefined ? req.body.${param} : null;
|
||||
if (${param} === null) {
|
||||
console.error(\`Missing parameter: ${param}\`);
|
||||
}`;
|
||||
}).join('\n ')}
|
||||
|
||||
let result;
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue