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 event on new row added to repeating section

1603653718

Edited 1603653875
Eric
Sheet Author
Hi ... I found this thread for exactly what I want to do ... <a href="https://app.roll20.net/forum/post/9079666/help-call-sheetworker-on-repeating-item-creation" rel="nofollow">https://app.roll20.net/forum/post/9079666/help-call-sheetworker-on-repeating-item-creation</a> Problem for me though is that it does not seem to be working. I don't get the change event triggered when the ADD button is clicked. Here's the snippet of the fieldset. I'm trying to use "newlogrow" as the triggering select ... &lt;fieldset class="repeating_lognotes"&gt; &nbsp; &nbsp; &lt;select name="attr_newlogrow" style="display: none;"&gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="default" selected&gt;default&lt;/option&gt; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value="default2"&gt;default2&lt;/option&gt; &nbsp; &nbsp; &lt;/select&gt; Here's the change event which is not triggering on the ADD button ... on('change:repeating_lognotes:newlogrow', function(eventInfo) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log("New row"); &nbsp; &nbsp; }); If I remove the display:none &nbsp;from the select style so that I can see the field on screen, then when I change the dropdown value to default2 then the trigger event fires, so I know that is working. Is this still a valid technique to detecting new rows? Thanks.
1603673959
GiGs
Pro
Sheet Author
API Scripter
This is still a valid technique. The issue is most likely that you are setting the select to display:none. It is not sensible to set a select to hidden - by nature, it's something players need to see to be able to select it. So, lets look at another way to solve your issue: what is this row for, what data will it eventually contain, and why do you need an event to fire?
1603678735
Eric
Sheet Author
I was/am using the display:none &nbsp;simple because the control was only to be used as the trigger initiating control; nothing the player needs to interact with, nor does it hold any usable data.&nbsp; Reading the linked post in my original above, that was a suggestion (to use display none). Albeit that was in reference to using a checkbox rather than a select. So I also tried a checkbox ... &lt;input type="checkbox" name="attr_newlogrow" value="x" checked/&gt; In any case, neither causes the trigger event on the ADD button.&nbsp; However both approaches would trigger the event when I manually check/select the control. As to what I'm trying to do is simple add the current date/time into a field in the fieldset row.&nbsp; This fieldset represents a log; the player would be adding entries by clicking the ADD button and when they do I want to auto-populate the date/time into the current row field. Thanks for your help.
1603682821
GiGs
Pro
Sheet Author
API Scripter
I made the suggestion to set display:none &nbsp;in that earlier thread, but I had never tested it that way. I'm guessing from your first post in this thread that it doesnt work though. Assuming that doesnt work, and getting back to your purpose: you want to add the current time. Is there anything else to go in this row? If so, the easiest way is to have the event fired when anything else is added to the row. If that wont work, you could have an action button outside the repeating section, that when clicked, adds a new row to the section and sets the time.
1603689953
GiGs
Pro
Sheet Author
API Scripter
I just tested this, and the select trick doesnt seem to be working, whether the select is visible or not. I'll have to try to find an old sheet where I have used this trick before, and see if it's still working, and try to figure out what's different. In the meantime, my last post suggests two ways to handle it. I'll expand on them here 1) I assume the players enter some data in this row. So, have the date saved on players entry of data. You can have it a textbox to hold the date, which a default value="". In your sheet worker, on('change:repeating_lognotes'), have a getAttrs line which checks this date field. If the date field is empty (===""), enter a date. If not, do nothing. 2) set up an action button to create a new row. That will use the&nbsp; <a href="https://wiki.roll20.net/Sheet_Worker_Scripts#generateRowID.28.29" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts#generateRowID.28.29</a> &nbsp;function, like on('clicked:logbutton', () =&gt; { &nbsp; &nbsp; const date = Date.now(); // (you want to format this date somehow) &nbsp; &nbsp; const rowid = generateRowID(); &nbsp;&nbsp;&nbsp;&nbsp;const output = {}; &nbsp;&nbsp;&nbsp;&nbsp;output[`repeating_lognotes_${rowid}_newlogrow`] = date; &nbsp; &nbsp; setAttrs(output); }); This assumes you have created a button named logbutton. Personally I'd change the newlogrow attribute name to something like logdate.
1603733660
Eric
Sheet Author
Hi ... thanks for the confirmation that the auto-trigger approach is not working. Yes, ahead of you there on the buttons. That was my original implementation which I was using.&nbsp; When I ran across that thread about auto triggering the change event I tried to convert to that approach. But alas since it does not work I'll just stay with the button approach. The auto-fill idea on when user enters data is interesting. I feel I'd need to make the logdate field (again the newlogrow was just the trigger control, not being used) as a read-only&nbsp; &lt;SPAN&gt; otherwise users not knowing it auto fills may needlessly be entering a date as the first thing they do every time they insert a row. I might do this, though. Thanks!