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

sheet has attr, but doesn't have attr?

1553818447

Edited 1553818490
So I have a simple worker that essentially is designed to set a default value if none exists. (One day maybe it'll be in sheet.json, but until then...) on("sheet:opened", function(eventInfo) { getAttrs(["sheettype"], function (values) {    if(!values.hasOwnProperty("sheettype")) { setAttrs({'sheettype':'typea'});    } }); }); However, the field in question is a <select> within the sheet, which defaults to its initial (or in lack of one, the first) value. This causes the script to tell me that getAttrs FINDS an attribute value for sheettype. Problem with that is that it doesnt populate that value into the hidden field with the same name (used for CSS purposes...), nor does it add said attribute to the "Attributes and Abilities" screen until that value is changed (and for the default, changed back). Is there a trick I'm missing here?
1553823812

Edited 1553823872
GiGs
Pro
Sheet Author
API Scripter
The best way to set a default value on a select is to add 'selected' to the value that is supposed to be the default. Like: <select name="attr_sheettype">     <option value="typea" selected>     <option value="typeb">     <option value="typec"> </select> Note that default values might not appear in the Attribute & Abilities tab (can't remember with selects, but they don't with inputs), but they do  still exist, and can be used in dice rolls and macros. Does that do what you need?
1553830884
GiGs
Pro
Sheet Author
API Scripter
Note: if you really need a way to set a default value in a sheet worker (I dont think you do), you could probably do it like this on("sheet:opened", function() { getAttrs(["sheettype"], function (values) { const validValues = ['typea','typeb','typec']; if(!validValues.includes(values["sheettype"])) setAttrs({'sheettype':'typea'}); }); }); Create an array of the valid values. If the current value isn't in that array, set it to the desired default.
1553866690

Edited 1553866850
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
In addition to what GiGs has said, simply add this to your hidden version of the attribute: Value='typea' This will be overwritten when the select's value changes. And, just going to reiterate something GiGs said; the attributes & abilities tab bears little relation to what attributes your character sheet has available to reference. Attributes that haven't changed from their default won't show up there and repeating attributes never show up there.
1554554840

Edited 1554554873
So I tried this with a radio button: <input type='hidden' name='attr_testx' class='sheet-wark'> <input type='radio' name='attr_testx' value="1" checked> <input type='radio' name='attr_testx' value="2"> <div class='sheet-div' style='height:150px; width: 150px;"></div> and CSS: .sheet-wark[value="1"] ~ .sheet-div {   background-color: red; } And the div does not color itself on load. If however the default value of the hidden is set, it does. So that would be the solution to the problem.
1554559056
GiGs
Pro
Sheet Author
API Scripter
As Scott suggested, try changing your hidden attribute to have a default value too, something like <input type='hidden' name='attr_testx' value="1" class='sheet-wark'> Leave the rest unchanged. See if that works on load.