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

Select from repeating section

I was wondering how I could create a select from a repeating section.
1673980265
GiGs
Pro
Sheet Author
API Scripter
Your question is vague. What do you mean?
I have a repeating section and I want to make a dropdown list from it inside the character sheet so I can select one among my repeating section. My repeating section are my abilities, and for each of my skills (an other repeating section), I need to select one of my abilities.
1673996265
Gauss
Forum Champion
Mellianor, alas your answer is still vague.  Here are some questions that may refine things:  1) Are you asking about creating (coding) a character sheet?  2) Are you asking about how to use a character sheet?  2a) If #2 is yes, which character sheet? If you do not know the name please post a screenshot so we can identify it. 
1674004700
GiGs
Pro
Sheet Author
API Scripter
I am guessing you are coding a sheet, but your question still lacks important details and I'm unsure how to answer it. If I'm understanding you, I see several issues. You have two repeating sections. In one section, there is a select you want to contain a list of options that is drawn from a specific item in the other repeating section. Is that correct? If so, say what the relevant attribute names are, and the names of the repeating sections.
1674006982

Edited 1674007017
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
It sounds like you are trying to have a dynamic list of skills and reference those skills in another dynamic list (your abilities). This unfortunately is not doable without quite a bit of legwork with javascript. The way you could  do this is to have the two repeating sections, have each of them contain a name attribute along with whatever bonus is going to be used. Then Use a text input for the user to enter the name of the skill that they want to associate with their ability. The sheetworker will then pick up the name and compare it to the names of the skills and then grab the appropriate bonus. It might look something like this (untested, likely doesn't address all edge cases, and very inefficient): HTML <fieldset class="repeating_skill"> <input type='text' name='attr_name'> <input type='number' name='attr_bonus'> </fieldset><fieldset class="repeating_ability"> <input type='text' name='attr_name'> <input type='text' name='attr_skill'> <input type='number' name='attr_bonus'> <input type='number' name="attr_skill_bonus"> <input type='number' readonly name='attr_total'> </fieldset> Sheetworker on('change:repeating_ability:skill change:repeating_skill:name change:repeating_skill:bonus',()=>{ // Get the row IDs for all of our skills getSectionIDs('repeating_skill',(skillIDs) => { // Assemble the complete skill row names const skillRows = skillIDs.map(id => `repeating_skill_${id}`) // Get all ability ids getSectionIDs('repeating_ability',(abilityIDs) => { // Assemble the complte ability row names const abilityRows = abilityIDs.map(id => `repeating_skill_${id}`); // Assemble an array of attribute names to get that will include all of our skill attributes and all the attributes necessary to calculate our ability totals const getArray = [...skillRows,...abilityRows].reduce((arr,row) => { arr.push(`${row}_name`); if(row.startsWith('repeating_ability')){ arr.push(`${row}_skill`,`${row}_bonus`); }else{ arr.push(`${row}_bonus`); } return arr; },[]) // Finally get the attributes from the database getAttrs(getArray,(attributes) => { // empty object that will store our changes so that we can apply them all at once. const setObj = {}; // Iterate over each ability row. Find the skill // that matches its skill entry and add that bonus // to the ability's bonus to get the total for // that ability abilityRows.forEach(abilityRow => { const skillRow = skillRows.find(sRow => attributes[`${sRow}_name`].toLowerCase() === attributes[`${abilityRow}_skill`].toLowerCase()); const skillBonus = +attributes[`${skillRow}_bonus`] || 0; setObj[`${abilityRow}_skill_bonus`] = skillBonus setObj[`${abilityRow}_total`] = skillBonus + (+attributes[`${abilityRow}_bonus`] || 0); }); // Apply our changes. I nearly always apply changes // silently to avoid unwanted setAttrs cascades. setAttrs(setObj,{silent:true}); }); }); }); }); This was thrown together pretty quick and is probably the most inefficient way to do this (or damn close). Some ways to improve the efficiency would be: Have a separate listener for each of ability skill entry change, ability bonus change, skill bonus change, and the skill name change. There's probably a better way to filter through all abilities and all skills to find the ones that match. (although doing the optimization above mostly negates the need for this)
I am coding a custom sheet and inside a repeating section (skills), I want a dropdown list that list the attribute name of an other repeating section (abilities). I don't want to have to spell the name of the ability, I want to select the ability from a select or an other dropdown list.
1674051748
GiGs
Pro
Sheet Author
API Scripter
The problem is, there is no way* to do that, which is why Scott provided the code that he did. Selects must be populated when the character sheet is designed , and that can't be modified during play. If you want a select that is dynamically expanding, that can't be done. *Or can it? It's also why I asked for the attribute and repeating section names. There might be a way to do something similar to what you want, using input datalists, but its complicated and prone to error, and I can't even start to provide the code without those names.
1674054169
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
We can't dynamically update the contents of selects or datalists. The only way I know of is what I outlined above.
1674074085
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: We can't dynamically update the contents of selects or datalists. The only way I know of is what I outlined above. We cant dynamically update datalists? That's a shame, I was looking forward to experimenting with those. In that case, it's not possible to do what OP wanted.
1674078578
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, and datalists can't be used with selects anyways.
1674078832
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: Yep, and datalists can't be used with selects anyways. No, I was intending to replace the select with an input.