Exploring my Form and Question classes has been an interesting journey. In my "Form" class, I store an array of questions and utilize a method called render() to display each one.
render() {
let htmlElement = document.getElementById("formBody");
let id = Question.GenerateID();
htmlElement.innerHTML += `
<div class="p-2">
<input type="text" class="input-transparent w-100" id="${id}.t" value="${this.Title}" placeholder="Unnamed question">
</div>`;
/**
* @param {int} id
*/
let questionNameChange = function(id) {
this.Title = document.getElementById(id + ".t").value;
};
document.getElementById(id + ".t").onchange = questionNameChange.bind(this, id);
}
Pictured below is the form that showcases these elements.
In troubleshooting, I've encountered an issue related to the element.onchange event which helps me modify question titles.
Despite adjusting input text fields for various questions, the title only updates on the last rendered question.
Could there be an error in my approach?