Add ability to set SELECT values

This commit is contained in:
Piper
2026-08-16 16:28:27 +02:00
parent bb77cd1e90
commit 3b93bbc44e
2 changed files with 22 additions and 3 deletions
+8
View File
@@ -10,6 +10,13 @@
<p>$textinterp</p>
<button title="$title" data-e6d-event-click="click buttonclick">A button with tooltip and onclick $textinterpfunc</button>
<p>Oh, look: a normal dollar sign: $. And then a dollar sign with no vars (does not resolve, emits error): $dollar</p>
<label>This should autoselect to 3</label>
<select data-e6d-value="$selectval">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
<option value="four">4</option>
</select>
</div>
</template>
<main>
@@ -40,6 +47,7 @@
},
title: `A title, injected`,
dynamicInterp: document.getElementById(`text-interp`).value,
selectval: `three`,
});
document.getElementById(`template-add`).appendChild(bind);
};
+13 -2
View File
@@ -67,10 +67,16 @@ class TemplateE6d extends HTMLTemplateElement {
} else {
const textTemplate = buildTextTemplate(node.getAttribute(attr));
if (textTemplate) {
bindAttr.push({
const bindLogic = {
attr: attr,
template: textTemplate,
});
};
if (node.nodeName === `SELECT` && attr === `data-e6d-value`) {
bindLogic.func = (el, val) => {
el.value = val;
};
}
bindAttr.push(bindLogic);
}
}
}
@@ -160,8 +166,13 @@ class TemplateE6d extends HTMLTemplateElement {
const injectTarget = resolve(templated, route.route);
for (const attr of route.bind.attr) {
const attrValue = templateString(attr.template, obj);
if (attr.func) {
attr.func(injectTarget, attrValue);
injectTarget.removeAttribute(attr.attr);
} else if (attr.template) {
injectTarget.setAttribute(attr.attr, attrValue);
}
}
for (const evt of route.bind.event) {
const trigger = evt.event;
const refFunc = obj[evt.reference];