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}}); }); }
Z
Zhellβ€’40d ago
Give all the inputs this name property:
name="system.bonus_progression"
name="system.bonus_progression"
Multiple inputs with the same name property will be combined into an array by the default form data handling of sheets I will say though, that since it is fixed size, I might recommend just using an object of keys (like "first", "second", "third", "fourth", ... or just numbers) instead of an array
C
Cynicideβ€’40d ago
Sorry, can you explain the term object of keys? Are you talking about changing the array in the template to an object with named keys?
Z
Zhellβ€’40d ago
I am, yes πŸ™‚
C
Cynicideβ€’40d ago
Thanks, I caught myself about to say Dictionary. But I wasn't sure if that was relevant outside Python. πŸ˜‚
E
Eranzielβ€’26d ago
Python dictionaries and JS objects are fairly equivalent. πŸ˜‰
Want results from more Discord servers?
Add your server
More Posts
hook preCreateToken update token nameI'm trying to update the token name when dropping a token on a scene. I basically have something lempty packSo I'm trying to access a pack in my module and it does exist but it's empty. My thoughts are 1. TError on package installError message ``` Error: Cannot read properties of null (reading 'protected') ``` I've started up Absolutely new to all of this, need help with a silly query.Hello! I'm extremely new to all of this, and i'm having issues trying to understand how to code a waHi, friends! I'd like to build a moduleHi, friends! I'd like to build a module and I could use a shove in the right part of the docs to go Well now I'm downloading lancerWell now I'm downloading lancerNew Entertainer - Fantasy if not Table Top ---- yetMy grandson is 11, and he has started making video shorts. This is his first full length YouTube stBoilerplate.css fileHi I started a new system from the Boilerplate system, and am having an issue seeing updates from myNewbie question on scopeHey there, total newbie here. I'm a complete amateur to programming. I've completed the todo tutoriaHaving trouble to get scripts loadedTrying to make my first module and I have troubles getting anything loaded in Foundry. Here is what Help Needed! Dynamic Table for Reputation TrackingHello, everyone. I am still encountering an issue with my Reputation Tracking system. In the actor Newbie questions on testing.Hi all, ive put together a simple module for PF2E that allows a user to favorite a spell, feat, itemTrouble with Synthetic Actors (unlinked tokens)When I create a token from an actor and try to update something like its hp, I get the following errAvoid Sheet Re-render When Editing Actor's Item**TL;DR** How do I avoid a re-render of a character sheet with actor.items displayed, that happens wHow to Create & Save Custom Field Values from a Dropdown on Actor sheet?I am building a custom system for a Hogwarts setting using the Wands & Wizards 5e supplement. I am cFinding target when making an attackI’m developing a game system, and can’t figure it out, when there is combat active and a player is t