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

Trigger sheetworker on new row, or other way to default value

1621559758
Jiboux
Pro
Sheet Author
Compendium Curator
Hi all, I have read the followed thread, but still doesn't answer what I am trying to do. <a href="https://app.roll20.net/forum/post/9341959/trigger-event-on-new-row-added-to-repeating-section" rel="nofollow">https://app.roll20.net/forum/post/9341959/trigger-event-on-new-row-added-to-repeating-section</a> I have in my sheet a repeating section repeating_spells for spells. In this section I have a select (could also be an input) SP_Circle, that gives the Circle (level in Eathdawn) of the spell On top of this section, I have a radio that works very well to make a filter on all the spells of certain level... When radio is 0, all the spells are shown, when radio 1, a CSS is filtering the repeating section to show only the Circle (level) 1 spell and so on... This works quite well except for one stuff: When you are filtered like this, and you click add for a new repeating section item, it doesn't appear except if you are in the radio 0 display. It makes sense because the new row initializes with a default value for the Circle (level), so the filter doesn't catch. I tried a sheetworker that triggered at any change of the repeating section, and if the Circle was still at the default value, would write the value of the radio in it, but it doesn't trigger when I click on add... Worse it triggers at the next action I am doing, so if I am trying to create a new level 4 spell, from the level 4 filtered view, nothing happens... But if now I click on the radio to display level 3 spells, the sheetworker now triggers and my new spell is here at the wrong level I saw in the above thread that clicking Add on a repeating section was actually not creating the line until a modification was done by the user... Any other suggestion how I could achieve the expected result (i.e. when adding a line from one of the filtered view, the new line is created and displayed with the desired value as per the filter)
1621566547

Edited 1621566802
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The way I handle this is by making a replacement add button, hiding the original add button, and then having a sheetworker react to the clicking of the custom add button to create a repeating item with all the default data I want in it. That looks something like this: HTML &lt;fieldset class="repeating_spell"&gt; &lt;!-- Yadda yadda yadda, repeating section details here --&gt; &lt;/fieldset&gt; &lt;div class="pseudo-control"&gt; &lt;button class="repcontrol_add" type="action" name="act_add_spell"&gt;Add&lt;/button&gt; &lt;/div&gt; CSS .sheet-pseudo-control{ --squaredim:10pt; justify-self:end; width:auto; font-size:var(--squaredim); min-height: 1em; } .sheet-pseudo-control{ grid-area:repcontrol; width:100%; } .sheet-whole .sheet-pseudo-control .sheet-repcontrol_add { border: medium none; background: none; box-shadow: none; font-size: 0; width:9px; height:13px; padding:0px; text-shadow:none; } .repcontrol{ &nbsp;&nbsp;&nbsp;&nbsp;display:none; } JS on('clicked:add_spell',(event)=&gt;{ &nbsp;&nbsp;&nbsp;&nbsp;getAttrs(['spell_filter'],(attributes)=&gt;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const setObj = {}; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let rowID = generateRowID(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setObj[`repeating_spell_${rowID}_circle`]=attributes.spell_filter;//You'll want additional restrictions here probably &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//set whatever other defaults you want &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setAttrs(setObj,{silent:true});//I always do {silent:true} on my setAttrs to avoid cascades. &nbsp;&nbsp;&nbsp;&nbsp;}); }); EDIT: You will of course probably want to restrict the CSS more than I did in this short demo, but it gets the point across. Edit the Second: I pulled the above html and CSS from a sheet using legacy sanitization. You'll need to adjust a bit for the new sanitization.
1621639708
Jiboux
Pro
Sheet Author
Compendium Curator
Thanks for the advice. Very cool indeed. I tried yesterday an alternative way : I modified my CSS filter so that the level 0 spells (i.e. the default value), appears in all filters... So now, when clicking the default add button in a filtered view, it appears... And as soon it is modified, the sheet-worker puts the default value.. But I keep the suggestion, as it could help me to solve other issues, thanks for the help !