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 .
×

Bug: Plain field updates are not always used in Dice Rolls

1670117134

Edited 1670120419
Jaz
Pro
I notice that some button rolls do not pick up updated `&lt;input type="number"` fields. This only occurs when popping the character sheet out of the game into its own popup window. Test HTML: &lt;h1&gt;Bug: Plain field updates are not used in Dice Rolls&lt;/h1&gt; &lt;h2&gt;Setup up character&lt;/h2&gt; &lt;ol&gt; &lt;li&gt;Open character sheet in a popout&lt;/li&gt; &lt;li&gt;Add a repeating field attribute&lt;/li&gt; &lt;/ol&gt; &lt;h2&gt;Demonstrate the bug&lt;/h2&gt; &lt;p&gt;IMPORTANT: This bug only occurs when the character sheet is popped out of the window&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Update the plain field value&lt;/li&gt; &lt;li&gt;Do not click away from field&lt;/li&gt; &lt;li&gt;Click on roll die button&lt;/li&gt; &lt;li&gt;Observe that the roll used the old field value&lt;/li&gt; &lt;li&gt;Expect that the roll used the updated field value&lt;/li&gt; &lt;li&gt;Compare to repeated field that works as expected&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;plain field&lt;/p&gt; &lt;div&gt; &lt;p&gt;Updating this input and then clicking the button &lt;b&gt;will not&lt;/b&gt; pick up the update &lt;b&gt;in popup window&lt;/b&gt;&lt;/p&gt; &lt;input type="number" name="attr_test1" value="0" /&gt; &lt;button type="roll" value="/roll 1d20 + @{test1}"&gt; &lt;/div&gt; &lt;hr /&gt; &lt;p&gt;Repeating fields&lt;/p&gt; &lt;fieldset class="repeating_skill"&gt; &lt;p&gt;Updating this input and then clicking the button &lt;b&gt;will&lt;/b&gt; pick up the update &lt;b&gt;in popup window&lt;/b&gt;&lt;/p&gt; &lt;input name="attr_skillmodifier" type="number"&gt; &lt;button type="roll" value="/roll 1d20 + @{skillmodifier}"&gt; &lt;/fieldset&gt; Example Playground: <a href="https://app.roll20.net/campaigns/campaignsettings/14386568" rel="nofollow">https://app.roll20.net/campaigns/campaignsettings/14386568</a> Any suggestions?
1670119976
vÍnce
Pro
Sheet Author
Hi Jaz, not sure if this is the cause of your issue, but suspect it is; your fieldset needs to be named using a class attribute, ie class="repeating_something"&nbsp; Otherwise roll20 doesn't recognize your repeating section appropriately in the vtt.&nbsp; more info <a href="https://wiki.roll20.net/Character_Sheet_Development/Repeating_Section" rel="nofollow">https://wiki.roll20.net/Character_Sheet_Development/Repeating_Section</a>
Ahh, sorry about that, I am trying to demonstrate a bug with a roll button in isolation, vs one in a `fieldset`. I'll replace the first one with a div.
Updated. Also, added the full code. It was cut off for some reason.
Video of issue
In other words, the issue only occurs in the `div` and not in a repeating section. (and only in a popup window)
1670121883

Edited 1670121959
GiGs
Pro
Sheet Author
API Scripter
I have seen different reports of strange behaviour with popped out character sheets. They do seem to be a source of problems. Is this related to the way changes arent detected in inputs until you click enter or jump out of the input to register the change? It would be worth checking though what other events cause the value to be updated. Does changing a value in another input cause the first input to now be updated, for instance? Clicking on the roll button should count as a change in focus sit it probably isnt that, I'm just thinking aloud. Also there does seem to be a different behaviour in fieldsets. Since everything (even the fieldset) is inside at least one div, it suggests it's the fieldset that is changing the behaviour not the div.
1670191957

Edited 1670192255
Oosh
Sheet Author
API Scripter
A couple of things - you have a default value in the first &lt;input&gt;, but not the second, so that's potentially skewing the result. Secondly, GiGs probably has the right of it - give both the inputs an id attribute so they're easy to target from the DOM, and attach regular 'change' listeners to both to see if they're triggering properly. There might be some DOM quirks with how change events propagate in an &lt;iframe&gt;. Finally, even if everything still looks normal, it's quite possible that clicking a roll button to trigger the 'change' event will lead to unpredictable behaviour. Setting the attribute from the 'change' event needs to be persisted to the database to become permanent, while (I believe) roll buttons just use the local version of the @{attribute}. It's possible that the roll button is just using the local value in browser while the attribute is updated, though I'm not really sure how the character sheet sandbox queues jobs, or whether roll commands check for dirty flags / stale values or similar. Edit - And it's just occurred to me that Roll20 uses jQuery for a lot of DOM events. One of the many reasons I think jQuery is awful (it was useful when Roll20 implemented it, not throwing shade here) is it has its own event system which doesn't mesh with the native JS DOM event system. This leads to unpredictable (ie bad) behaviour when combining the two. If you experiment with DOM event handlers for the inputs, it might be worth also attached jQuery handlers to both the &lt;inputs&gt; and &lt;buttons&gt; to see if there's anything screwy going on with the timing.
I agree, something unusual is happening, and possibly related to jQuery. What is odd to me is that this only occurs when popping the character out into a window. (See&nbsp; Video of issue ). In any case, I have corrected the code to make this apples-to-apples. I also added `id` to no avail: &lt;h1&gt;Bug: Plain field updates are not used in Dice Rolls&lt;/h1&gt; &lt;h2&gt;Setup up character&lt;/h2&gt; &lt;ol&gt; &lt;li&gt;Open character sheet in a popout&lt;/li&gt; &lt;li&gt;Add a repeating field attribute&lt;/li&gt; &lt;/ol&gt; &lt;h2&gt;Demonstrate the bug&lt;/h2&gt; &lt;p&gt;IMPORTANT: This bug only occurs when the character sheet is popped out of the window&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Update the plain field value&lt;/li&gt; &lt;li&gt;Do not click away from field&lt;/li&gt; &lt;li&gt;Click on roll die button&lt;/li&gt; &lt;li&gt;Observe that the roll used the old field value&lt;/li&gt; &lt;li&gt;Expect that the roll used the updated field value&lt;/li&gt; &lt;li&gt;Compare to repeated field that works as expected&lt;/li&gt; &lt;/ol&gt; &lt;p&gt;plain field&lt;/p&gt; &lt;div&gt; &lt;p&gt;Updating this input and then clicking the button &lt;b&gt;will not&lt;/b&gt; pick up the update &lt;b&gt;in popup window&lt;/b&gt;&lt;/p&gt; &lt;input type="number" name="attr_test1" id="attr_test1" /&gt; &lt;button type="roll" value="/roll 1d20 + @{test1}"&gt; &lt;/div&gt; &lt;hr /&gt; &lt;p&gt;Repeating fields&lt;/p&gt; &lt;fieldset class="repeating_skill"&gt; &lt;p&gt;Updating this input and then clicking the button &lt;b&gt;will&lt;/b&gt; pick up the update &lt;b&gt;in popup window&lt;/b&gt;&lt;/p&gt; &lt;input type="number" name="attr_skillmodifier" id="attr_skillmodifier" &gt; &lt;button type="roll" value="/roll 1d20 + @{skillmodifier}"&gt; &lt;/fieldset&gt; One observation, if I go into the browser debugger and manually add `onclick="this.focus()"`, then the UI works as expected. Unfortunately, character sheet sanitizing appears to remove `onclick`