Cynicide
Cynicide
Using an array in a sheet template
In the system I am creating, the progression of a skill category is handled with a fixed size array of values. I can create this array in template.json and render it on the sheet as input elements. However when I update the array based on user input I need to write an event handler to do it, I can't just change the value in the input box and have my Document update. Is there an easier way than this? This is the current implementation: Template <div style="display:flex; flex-direction: row;"> {{#each system.bonus_progression}} <input class="skillcat_bonus_progression_input" type="text" value="{{this}}" data-dtype="Number"/> {{/each}} </div> Javascript activateListeners(html) { super.activateListeners(html); html.find('.skillcat_bonus_progression_input').change(ev => { let bonusProgression = []; let bonusProgressionInput = html.find('.skillcat_bonus_progression_input'); for (let i = 0; i < bonusProgressionInput.length; i++) { bonusProgression.push(bonusProgressionInput[i].value); } this.object.update({system: {bonus_progression: bonusProgression}}); }); }
8 replies