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

Referencing a hidden field using @{AttributeName} syntax is stripping non-numeric characters

I have these two input fields: <input class="attribute-bonus" type="text" value="@{psSupernaturalBonus}" name="attr_psSupernaturalBonus_disabled" title="Supernatural MDC Damage" disabled="true" /> <input type="hidden" name="attr_psSupernaturalBonus" value="" /> When the value of `attr_psSupernaturalBonus` is "3D6", the value of `attr_psSupernaturalBonus_disabled` is "36". "2D6" becomes "26", etc. What am I missing? Is there a different way to reference another input value than `@{AttributeName}`?
1622678572
GiGs
Pro
Sheet Author
API Scripter
When you have a disabled attribute, it tries to calculate it's value. So if psSupernaturalBonus was entered as "3*2", the psSupernaturalBonus_Disabled value would be "6". Because of this, it does strip out letters that it cant make sense of - it assumes it is being given numerical values, so the "d" is removed. The best way to do what you want is with a sheet worker. But before suggesting a code solution, can I ask why the psSupernaturalBonus is hidden? How is it being set if it is hidden?
Hi. Thanks for the reply. It's being set by a Sheetworker and `setAttrs()` in an `on("change:ps")` event handler. Originally I was just using one field, but `setAttrs()` has a problem with disabled fields, so I used the trick in the Sheetworker docs -  Note: If you are trying to update a disabled input field with this method you may run into trouble. One option is to use this setAttrs method to set a hidden input, then set the disabled input to the hidden element. Ideally what I want is for `setAttrs()` to calculate the value of `psSupernaturalBonus` and set it directly, on the disabled field itself.
1622679675
Finderski
Pro
Sheet Author
Compendium Curator
Instead of making the field disabled, make it read only 
Finderski said: Instead of making the field disabled, make it read only  That worked like a charm. Thanks!
1622680437
GiGs
Pro
Sheet Author
API Scripter
and that means you dont need the hidden attribute any more.
GiGs said: and that means you dont need the hidden attribute any more. Correct. I've already killed it :)