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

Displaying reapeating attributes in a select

Hello the community, I've wrote this piece of code in order to collect data from a repeating section in the worker sheet section : on('sheet:opened',function(){         getSectionIDs("repeating_closecombatdisc", function(idarray) {             for(var i=0; i < idarray.length; i++) {                         _.each(idarray, function(currentID) {                                 getAttrs(["repeating_closecombatdisc_"+currentID+"_discname", "repeating_closecombatdisc_"+currentID+"_disc"], function(values) {                                                 console.log(currentID);                         console.log("Name : "+values["repeating_closecombatdisc_"+currentID+"_discname"]);                         console.log("Value : "+values["repeating_closecombatdisc_"+currentID+"_disc"]);                                         });                         });         }             }); }); It works perfectly. In the end. I have the name and the value I want. Now, I'm trying to insert these values in an input select, in another part of my character sheet, outside the repeating section (id = -m37den82v-lfu5fukmj). <select name="attr_CurrentWeapon" class="sheet-select_2">                     <option value="@{repeating_closecombatdisc_-m37den82v-lfu5fukmj_disc}">@{repeating_closecombatdisc_-m37den82v-lfu5fukmj_discname}</option>                    </select><input class="sheet-skill-off" type="number" name="attr_CurrentWeaponDisplay" value="@{CurrentWeapon}" disabled="true"/> At this point, I can't manage to make this works : - @{repeating_closecombatdisc_-m37den82v-lfu5fukmj_disc} - @{repeating_closecombatdisc_-m37den82v-lfu5fukmj_discname} are not resolved. Can you help me understand what's wrong ? Thanks
In order to give more details. The objective is to build select input with options based on values collected in a repeating section of a cheracter sheet.
1587129448
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Unfortunately, this is not possible as selects on character sheets are not dynamic, they can only be hard coded. You can create a pseudo select, but it's a lot of work for not much pay off.
1587130075
GiGs
Pro
Sheet Author
API Scripter
The main stumbling block for you is this: Select values must be set at the sheet's design time, they cannot be updated later.  There are ways to do this on other websites. But roll20 locks down what we can do very tightly, and this is one of the things we just cant do. That aside, a generla tipe: you should never put getAttrs or setAttrs inside a loop, never mind two loops, like in the _.each code you have above. getAttrs and setAttrs are both very slow commands, and putting them in a loop compounds this. Its best to structure your code so they are outside any loops. If you want to know how to rewrite that code, I can give an example, but it's not relevant to this problem, which is the fact you cant do what you want to do. Believe me, there's plenty of that would love to have dynamically updating selects, it's just not possible on roll20.
Thank you guys for your answers. If you have an elegant piece of code to improve mine, that's ok !
1588112224
GiGs
Pro
Sheet Author
API Scripter
We could make the sheet worker look more elegant, but the main problem is, it won't work no matter what we do. You cant have selects that update dynamically. You have to have the select's option text and values defined when the sheet is created. You need to come up with a different approach, then we can help with the code. We dont know enough about what the sheet is doing to suggest alternatives.