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

eventInfo.previousValue Bug?

1543745931
Finderski
Pro
Sheet Author
Compendium Curator
I'm working on a sheet worker and am using newValue and previousValue to help simplify some work and I found that when I initialize a repeating row and change the value of the field being watched, the newValue is correct (meaning, the value I entered in the blank field matches newValue), but previousValue is incorrect (meaning, it has the same value I entered in the blank field). The html field being watched: <input class="sheet-armorWeight" type="number" name="attr_ArmorTypeWeight" title="@{repeating_armor_$#_ArmorTypeWeight}" /> And here's the console log: Made it to Armor Type Weight Change VM17:430 New Value: 15 VM17:431 Previous Value: 15 This this be happening?  It seems odd that it should be.  I suppose I could set a default value, but I'd rather not do that if I don't have to...
1543805100
Pat
Pro
API Scripter
What are you referencing for the value? Do you have the value assignment script handy? 
1543809292
Finderski
Pro
Sheet Author
Compendium Curator
Pat said: What are you referencing for the value? Do you have the value assignment script handy?  Not sure I understand the question...not doing any value assignment. I'm entering a value in the input field, which is triggering the on change portion of the sheet worker. To be a little clearer, start with a blank input field, then enter a number in the input field and press enter (or click out of the field) and watch the console log be wrong.
1543849604
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
Do you also have " ArmorTypeWeight_max " ? because the max value triggers on the same change event.  I would also double check that on change: armortypeweight  only on change that is calling that routine and that it is not being also called by another routine that is also being triggered.  And maybe post the  sheet worker routine as well.  Also, are you sure your console log is showing that the routine was being entered only once? At one point I noticed that my routines were being entered twice when entering a previously non-existing value, and the 2nd time, but I thought that weirdness went away years ago (or maybe I just stopped noticing it). 
1543852867
Finderski
Pro
Sheet Author
Compendium Curator
I'm not using _max, so that shouldn't be triggering anything. change:repeating_armor:armortypeweight  is only being called in one spot, no other routines are calling/watching/responding to  At work at the moment, I'll post the code later. As near as I can tell, the console log is only showing the routine being called once; I make sure to mark my place in the console before executing the change so I know exactly where the console log report starts and I only see it show up once.  
1543856840
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Finderski, This is because repeating attributes don't exist until they have a value. You could try putting a default value in that html declaration and see if that causes it to give the correct previousValue. Other wise simply put logic in that if newValue = previousValue act as if it's a new row.
1543857375
Finderski
Pro
Sheet Author
Compendium Curator
Thanks Scott C, I was afraid that was going to be the answer.  Doesn’t make sense, logically—to me anyway, if it didn’t exist previously, you’d that would be NaN or undefined or even 0, but it is what it is.  I know that defining a default value seems to work.
Hey, I came across the same problem ... I have an input inside a repeating section, with a default value = 0 : <input type="number" name="attr_temp_courage" value="0"> - when the attribute doesn't exists, if i focus then blur the field WITHOUT any changes, it still triggers the onchange event with previousValue = 0 and newValue = 0, then the attribute exists. - when the attribute dosn't exists, if i focus, change the value (e.g : 2) , then blur, it's trigger the onchange event with previousValue = 2 and newValue = 2 EVEN with the default value=0 ! - if the attribute already exists, there is no problems.