I am creating a fill in the blank type game using vue. Where a based on a JSON file question the _ in the question are replaced with inputs. I am having trouble with using multiple input fields in my question.
I initialize an empty array for user input and then add an increment to the userInput value so they can be unique. When I start typing and look into the vue console it creates an array of 3 userInputs (There should only be 2, 1 for each input) And it also only fills the last item in the userInput Array 1.
I feel like a I am close and the answer lies somewhere in how I use my domProps and on: {} call but having trouble find docs on my situation. I have simplified my example to exclude the JSON for simplicity. Any help or direction is appreciated.
Here is an link to a sandbox example I have placed the code in app.vue
<template>
<div class="interactive interactive-vue-question interactive-vue-question-iv">
<ivInput v-bind:class="'iv-input-wrapper'"></ivInput>
</div>
</template>
let ivInput = {
name: "iv",
render: function(createElement) {
let arr = [];
let question = 'Old *_* had a *_*';
let questionArray = question.split("*");
let myInput
let currentAnswer = 0
//Filter/Remove any Empty or Null values
questionArray = questionArray.filter(function(e){return e})
for (let q in questionArray) {
//If there is no _ wrap the text in a span and push it to the array
if (questionArray[q] != "_") {
let questionText = arr.push(createElement("span", questionArray[q]));
}else{
myInput = createElement("input", {
attrs: {
type: "text",
// disabled: this.isSuccess
},
domProps: {
//Get the value of the component/input
value: this.userInput[currentAnswer],
name:"iv-"+ currentAnswer
},
//Event triggers
on: {
input: e => {
this.userInput[currentAnswer] = e.target.value
}
},
})
arr.push(myInput)
currentAnswer++
}
}//end for loop
return createElement("div", arr);
},
data: function() {
return {
userInput: [],
errorMessage: "",
//answers: this.cData.body.answers,
// type: this.cData.body.type,
//typeErrorMessage: this.cData.body.typeErrorMessage,
// case: this.cData.body.case,
//accent: this.cData.body.accent
};
},
props:['cData'],
}//End iv
export default {
name: "iv-v1",
props: ["cData"],
components: {
ivInput
},
data: function() {
return {};
},
};