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

Initialize Attribute

1611804288
Jiboux
Pro
Sheet Author
Compendium Curator
Hi, Still developping a new version of the existing Earthdawn sheet. I begin to have a lot done, but there is a bug that I keep having. There is an extensive use in the sheet of local test values using test boxes.  Let's take the following idea : I have an attribute called attr_actiontype, that is entered somewhere in my sheet <input type="number" name="attr_actiontype" value="0" title="Enter 1 if it is an action; 2 if it is damage and 0 if it is neither"> Let's say now that I have another section of the sheet where there are parameters that are only used if it is an action. What would be done would be to test the value with a checkbox and display depending on the result <input type="checkbox" name="attr_actiontype" value="1" hidden class="testChecked"> <span class="HideIfNotChecked"> This section is only useful if Action</span> With styles .sheet- testChecked:not(:checked)  ~ .sheet-HideIfNotChecked {display:none;} With this code, when the first number input is changed, the roll20 attribute is also changed, and the checkbox input will detect if the attribute value is 1 or not, checking itself automatically and triggering the display or hiding of the span... BUT this seems to not work at startup. When I load my HTML sheet, it seems that all the inputs default to their defined "value" ( or for checkboxes to their default status), and the connexion done via the roll20 attribute doesn't happen until something in the sheet is changed, and suddenly all inputs seem to synchronize to the database of attributes. So here for example, if I was entering 1 as value for the first input, the span would display... But if I would reload  my code, the checkbox would temporarly loose the connexion to attr_actiontype, and could "forget" to display the span until an action was forcing it to pull from the database... Anyone else experienced such behaviour and has hints how to solve it ? Maybe I missed it on the Wiki
I could be wrong, but I believe all you need to do is convert your input elements to type="radio" so that the value attribute can be interpreted the way you expect it to by the browser.
1611969743
GiGs
Pro
Sheet Author
API Scripter
There's something weird about your checkbox: <input type="checkbox" name="attr_actiontype" value="1" hidden class="testChecked"> What is that word hidden doing there? Roll20 will be either ignoring it, but maybe it is messing up the way the input works. If its meant to be a hidden input, it should be <input type="hidden" name="attr_actiontype" value="1" class="testChecked"> Then in your CSS you check for its value, not its checked status, like  .sheet- testChecked:not([value="1"])  ~ .sheet-HideIfNotChecked {display:none;}
1612126188
Jiboux
Pro
Sheet Author
Compendium Curator
I have plenty of hidden inputs that help conditional formatting... Some are type="hidden", others are "hidden" or class="hidden"... The CSS is done to interprete all of those as display:none;  and normally  Display:none;  inputs still get interpreted... But could there be a difference here ?
1612127207
GiGs
Pro
Sheet Author
API Scripter
inputs with type hidden work differently from all other inputs, and are designed to handle dynamically updating attributes. Generally, if you doing something with css depending on the value of the attribute, and its not working, you should try it with a type="hidden" input. 
1612128788
Jiboux
Pro
Sheet Author
Compendium Curator
Interesting... Where I am stuck is that in many of my applications I need it to be a type="checkbox". I'll very often have an attribute set somewhere in the sheet (either a number/text value, or also a checkbox) and somewhere else in the sheet the same attribute as a hidden checkbox that triggers a conditional formatting... If the type is now hidden, it looses the "checked/unchecked" property of the checkbox, so I can't make my CSS anymore. I saw your answer on testing the value on the CSS, but in the tries I did the CSS is only able to test a value if this value has been set by a sheetworker, not by another input that refers to the same attribute. Is there a trick to do that I missed ?
1612131447

Edited 1612131619
GiGs
Pro
Sheet Author
API Scripter
I dont use the checked/unchecked property very often. My example in my first post in this thread showed how to use value instead of checked. Jiboux said: I saw your answer on testing the value on the CSS, but in the tries I did the CSS is only able to test a value if this value has been set by a sheetworker, not by another input that refers to the same attribute. Is there a trick to do that I missed ? You dont need to set the hidden value. Just give it the same name as the checkbox. Like <input type="checkbox" name="attr_something" value="1"> <input type="hidden" name="attr_something" value="0"> Here I have created a checkbox and a hidden attribute, both with the same name. the hidden input will automatically have the same value as the checkbox.  They have different values, because I want to set a default value of 0. the value in a checkbox doesnt set its default value, it sets the value it will have when you check it. The hidden  attribute therefore sets the value it has when it is not checked. Also, this kind of CSS value checking only works when using hidden inputs IIRC. They are designed to work this way. CSS in roll20 reads the value of attributes set in the html, and ignores what you change the value to later. hidden attributes are able to read the attributes actual value, and so are essential once you start checking for values in CSS.
1612153571
Jiboux
Pro
Sheet Author
Compendium Curator
Interesting... I didn't know about the type="hidden". I made some tries and it opens some interesting possibilities I understand the value field of the checkbox being the value when checked, and not an initiatilization value. I know you can initialize the checkbox with checked/unchecked or with checked="true" or even checked="checked" I know do understand that a CSS test on value will be able to read the up to date attribute value if taken from an input type="hidden". Question : is there a way to make it with an autocalc value ? We have a CSS "redGreen" that based on value is turning a buff/debuff in red when negative and green when positive. We use it both for manually entered modifiers, and for automatically calculated ones (below example with Auto being calculated automatically, hence why it is readonly, as it is calculated in a sheet-worker)             <input name="attr_T_Mod-Auto" type="hidden" class="redGreen" value="0">             <input name="attr_T_Mod-Auto" type="number" readonly class="buffLeft">             <input name="attr_T_Mods" type="hidden" class="redGreen" value="0">             <input name="attr_T_Mods" type="number" class="buffRight"> For the Manual Modifier T_Mods we never had a problem, but for the automatic T_Mod-Auto, initially we had it as an autocalc input             <input name="attr_T_Mod-Auto" disabled type="hidden" class="redGreen" value="(@{attr_Mod-Type} + @{attr_Special-Mod})"> but we were never able to make the automatic formatting on the CSS work based on the auto-calculated value, and found no better way than moving the calculation to the sheet-worker.
1612155751
Andreas J.
Forum Champion
Sheet Author
Translator
Jiboux said: Interesting... I didn't know about the type="hidden". I made some tries and it opens some interesting possibilities <a href="https://wiki.roll20.net/Building_Character_Sheets#type.3D.22hidden.22" rel="nofollow">https://wiki.roll20.net/Building_Character_Sheets#type.3D.22hidden.22</a> It's documented. Question : is there a way to make it with an autocalc value ? Probably, but not a good idea. It's better to have sheetworkers. Auto-calc values have several problems, like how tokens can show their values in their bar, and sheetworkers can't process them well either. The behavior you found isn't surprising to me given auto-calc's track record. <a href="https://wiki.roll20.net/Auto-Calc" rel="nofollow">https://wiki.roll20.net/Auto-Calc</a> If your observasion isnt on the wiki page, you could edit it and add your findings to the collective wisdom of the community for others to find.
1612184623
Jiboux
Pro
Sheet Author
Compendium Curator
Thanks that s à point i had missed in the wiki