fix: checkbox data content

This commit is contained in:
obvTiger 2025-03-28 16:03:05 +01:00
parent 79a7f92ff9
commit 9155b79ec9
3 changed files with 72 additions and 5 deletions

View file

@ -55,6 +55,23 @@ class InputElementGenerator {
attributes = ' type="range"';
}
// Extract and handle ID attribute
let idAttr = "";
const idProp = node.props.find(p => typeof p === "string" && p.startsWith("id:"));
if (idProp) {
const idValue = idProp.substring(idProp.indexOf(":") + 1).trim().replace(/^"|"$/g, "");
idAttr = ` id="${idValue}"`;
node.elementId = idValue;
// Register as reactive element with the parent generator
if (this.parentGenerator && this.parentGenerator.jsGenerator) {
this.parentGenerator.jsGenerator.registerReactiveElement(idValue);
if (this.options.debug) {
console.log(`[InputElementGenerator] Registered checkbox with ID: ${idValue} as reactive`);
}
}
}
const valueProp = node.props.find((p) => p.startsWith("value:"));
if (valueProp) {
const value = valueProp.substring(valueProp.indexOf(":") + 1).trim();
@ -70,7 +87,7 @@ class InputElementGenerator {
if (node.children.length > 0) {
let html = `<label class="${className}-container">`;
html += `<input class="${className}"${attributes}>`;
html += `<input class="${className}"${attributes}${idAttr}>`;
node.children.forEach((child) => {
child.parent = node;
@ -80,7 +97,7 @@ class InputElementGenerator {
html += `</label>`;
return html;
} else {
return `<input class="${className}"${attributes}>`;
return `<input class="${className}"${attributes}${idAttr}>`;
}
}
}