better event managment

This commit is contained in:
rewin
2024-02-13 22:13:46 +03:00
parent 5e5a6796f6
commit f78f4b8136
3 changed files with 179 additions and 85 deletions
+5 -4
View File
@@ -16,8 +16,9 @@ function unpack_vnode(
var attr = node_data["attributes"][i];
element.setAttribute(attr[0], attr[1]);
}
element.setAttribute("onchange_id", node_data["onchange"]);
console.log("onchange", node_data["onchange"]);
if (node_data["id"] != undefined) {
element.setAttribute("id", node_data["id"]);
};
//apply children
if (node_data["children"] != undefined) {
for (var j = 0; j < node_data["children"].length; j++) {
@@ -27,10 +28,10 @@ function unpack_vnode(
}
}
//add onchange hook if input
if (node_data["tag"] == "input") {
if (node_data["onchange"] == true) {
element.onchange = (event: Event) => {
var input = event.target as HTMLInputElement;
const id = input.getAttribute("onchange_id");
const id = input.getAttribute("id");
if (id != null) {
console.log("onchange", id, input.value);
const value = input.value;