Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Repeating sections and setting a description

Hi there, Let me explain what I'm try to achieve. Let's say I have this repeating section. <fieldset class="repeating_sac">     <select name="attr_contenu">         <option value="">-- Objets disponibles --</option>         <option value="Marteau">Marteau</option>         <option value="Epée">Epée</option>         <option value="Arc long">Arc long</option>         <option value="Bile de dragon">Bile de dragon</option>         <option value="Carquois">Carquois</option>         <option value="Torche">Torche</option>     </select>     <input type="text" name="attr_description" value="@{description}" readonly /> </fieldset> Somewhere inside my worker, I have these datas : const stuffData = {         "Marteau": {             "type" : "arme",             "description" : "Arme de mêlée"         },         "Epée" : {             "type" : "arme",             "description" : "Arme de mêlée"         },         "Arc long" : {             "type" : "arme",             "description" : "Arme à distance"         },         "Bile de dragon" : {             "type" : "divers",             "description" : "Permet d'enflammer"         },         "Carquois" : {             "type" : "divers",             "description" : "relance les dés"         },         "Torche" : {             "type" : "divers",             "description" : "Permet de prendre 2 cartes en fouilles ou enflamer une bile"         }     } I would like to update the description part of the repeating section (the "text input" tag) with the description contained in my datas. My entry point would probably be this on("change:repeating_sac remove:repeating_sac sheet:opened", () => {         getSectionIDs("repeating_sac", (idarray) => {             getAttrs(idarray.map((id) => `repeating_sac_${id}_contenu`), (values) => {                 .....             });         });     }); but I'm in a black hole concerning the dots ..... Is it doable ? If yes, how ?
1547851944

Edited 1547862286
GiGs
Pro
Sheet Author
API Scripter
Firstly this part needs to be altered <input type="text" name="attr_description" value="@{description}" readonly /> Its refering to itself, and should really be something like <input type="text" name="attr_description" value="" readonly /> Secondly, your worker is a bit more complicated than it needs to be. When you are changing something on the same row of a repeating fieldset, you dont need to use getSectionIds (though yours is an elegant way to structure it for when you do need it). You can use on("change:repeating_sac:contenu sheet:opened", () => {     getAttrs(['repeating_sac_contenu'], (values) => {         let contenu = values['repeating_sac_contenu'];         let desc = stuffData[contenu].description; //also valid: stuffData[contenu]['description']         setAttrs({             repeating_sac_description: desc         })     }); }); When omitting the row id, notice the different syntax used on the change line, and everywhere else: on change line: replace _id_ with : everywhere else: replace _id_ with _
Thanks man, it does the trick !! Bonus is I can understand the code ;)
1547928531
GiGs
Pro
Sheet Author
API Scripter
You're welcome! I do generally avoid more advanced code syntax unless necessary, because most of us here are self-taught newbies, and code you can understand and reuse is better than "better" code that is hard to understand.