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 Worker "If Not"

I am trying to get a drop down menu to activate a checkbox.  The drop down menu has three options, each with a value of "1", "2", and "3".  And its all contained in a repeating field.  This is what I got. //Torpedeo on("change:repeating_shipweapon:shipweaponstyle1 sheet:opened", function() { getAttrs(["repeating_shipweapon_shipweaponstyle1","repeating_shipweapon_torpedo_open"], function(values) { if (values.repeating_shipweapon_shipweaponstyle1 == 3) { setAttrs({ repeating_shipweapon_torpedo_open: 1 }) } else { setAttrs({ repeating_shipweapon_torpedo_open: 0 }); } }); }); Any thoughts?
1541800442

Edited 1541801066
GiGs
Pro
Sheet Author
API Scripter
What's the html and CSS for the dropdown and checkbox ? Also, just for good practice, I'd use only one setAttr call. In this function it doesnt matter too much, but it looks cleaner to me and is easier to write, i think, once you're used to it. on("change:repeating_shipweapon:shipweaponstyle1 sheet:opened", function() { getAttrs(["repeating_shipweapon_shipweaponstyle1"], function(values) { let worker = 0; if (parseInt(values.repeating_shipweapon_shipweaponstyle1, 10)||0 === 3) worker = 1; setAttrs({ repeating_shipweapon_torpedo_open: worker }); }); }); I added parseInt there, but its probably unnecessary if those values are coming from a dropdown. You also dont need to get the value of torpedo_open in the getAttrs line, since the function doesnt refer to the original value. It only sets the new value.
That did not work.  As I don't know why the other way didn't work, I don't know why this didn't either. html of check box and section I want to hide <input type="checkbox" class="sheet-open" name="attr_torpedo_open" checked /> <div class="sheet-hold" html of drop down <div class="sheet-item sheet-110"> <select name="attr_shipweaponstyle1" class="charaselect"> <option value="1">Macrobattery</option> <option value="2">Lance</option> <option value="3">Torpedoes</option> </select> </div> Relevant css of Checkbox  input.sheet-open:checked ~ div.sheet-hold { display: none; }
1541802599
GiGs
Pro
Sheet Author
API Scripter
Try giving your checkbox value=1, so <input type="checkbox" class="sheet-open" name="attr_torpedo_open" value="1" checked />
1541802701
GiGs
Pro
Sheet Author
API Scripter
Also, just to be clear: what part isnt working? I'm working on the assumption that the checkbox isnt being checked and unchecked properly. Is that correct?
G G said: Try giving your checkbox value=1, so <input type="checkbox" class="sheet-open" name="attr_torpedo_open" value="1" checked /> Oh for Pete's sake ...okay, that fixed the sheet worker.  Yers didn't work, but I screwed up on how the dropdown/sheet worker interaction operates.   So, thank you so much for your help.  I was ready to figure out how to get code to manifest in reality so I can shoot it.
1541803258

Edited 1541803406
GiGs
Pro
Sheet Author
API Scripter
It's the little things that drive is the most crazy. To be clear, you dont always need a value statement in checkboxes, but when setting their values in sheet worker code, you do. Without the value=1 (or some other value), it will have the value "on" when checked. 
And now I know.
1541809826
Andreas J.
Forum Champion
Sheet Author
Translator
G G said: To be clear, you dont always need a value statement in checkboxes, but when setting their values in sheet worker code, you do. Without the value=1 (or some other value), it will have the value "on" when checked.  Ooh, that's why they have to have the 1s there, never knew. 
1541818603
Finderski
Pro
Sheet Author
Compendium Curator
Coal Powered Puppet said: Oh for Pete's sake ... I'm glad I'm not the only one who says that! LOL Also, I believe you use checkboxes in sheet workers without a value, but then the value is either 0 or 'on'. At least in some of my sheet workers I set them to 'on' when I haven't declared a value and it works...
1541820507

Edited 1541820588
Coal Powered Puppet
Pro
Sheet Author
Finderski said: Coal Powered Puppet said: Oh for Pete's sake ... I'm glad I'm not the only one who says that! LOL To be honest, "Pete" was NOT the first word I thought of.
1541849086
Finderski
Pro
Sheet Author
Compendium Curator
LOL I totally understand...but you still thought of it. xD
1541853257
Jakob
Sheet Author
API Scripter
You should delete the "sheet:opened" part of the event string, this won't work anyway with a global event.
1541867728
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
CPP, If the checkbox doesn't need to be displayed and the section that you are controlling the display of are in the repeating section, then you don't even need sheetworkers to do this, simply change your code to this: <input type="hidden" class="sheet-open" name="attr_shipweaponstyle1"/> <div class="sheet-hold" html of drop down <div class="sheet-item sheet-110"> <select name="attr_shipweaponstyle1" class="charaselect"> <option value="1">Macrobattery</option> <option value="2">Lance</option> <option value="3">Torpedoes</option> </select> </div> Relevant css of Checkbox  input.sheet-open:checked ~ div.sheet-hold, input.sheet-open[value=3] ~ div.sheet-hold { display: none; } Not sure of the context of your code, so this may not be appropriate, but just wanted to throw it out there.
Scott C. said: Not sure of the context of your code, so this may not be appropriate, but just wanted to throw it out there. The activating dropdown menu is in a different <div> than the checkobx/input, so I used a sheet worker "jump the fence".  But thank you, I didn't know how to use an input value in css before. Thank you to everyone who helped out.  The code looks fairly sexy now.
Scott C. said: Relevant css of Checkbox  input.sheet-open:checked ~ div.sheet-hold, input.sheet-open[value=3] ~ div.sheet-hold { display: none; } Not sure of the context of your code, so this may not be appropriate, but just wanted to throw it out there. Say...could I use this fancy shancy bit with a text or number box? Just change what's in the text box and the if the value matches the css code, it changes?
1542239777
GiGs
Pro
Sheet Author
API Scripter
I think it should work, there's an easy way to find out! Make sure to surround the text with quotes, e.g. input.sheet-open[value="some text here"] ~ div.sheet-hold
1542243283

Edited 1542243470
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Coal Powered Puppet said: Scott C. said: Relevant css of Checkbox  input.sheet-open:checked ~ div.sheet-hold, input.sheet-open[value=3] ~ div.sheet-hold { display: none; } Not sure of the context of your code, so this may not be appropriate, but just wanted to throw it out there. Say...could I use this fancy shancy bit with a text or number box? Just change what's in the text box and the if the value matches the css code, it changes? Unfortunately not directly. Other input types don't directly update their value in the html, so the CSS reacts as if they were still set to their defaults. You can however make a copy of the input or select and make it type=hidden and then base any css off the hidden version. Edit: to be clear, you can do it with any type of data, the important part is that the input be type=hidden. You can also use any of the selectors found here
Yep.  After some trial and error- and spelling mistakes- it works.  Thank you both very much.