Sheet Worker "If Not"

1541769586
Coal Powered Puppet
Pro
Sheet Author
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
G G
Pro
Sheet Author
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.
1541801548
Coal Powered Puppet
Pro
Sheet Author
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
G G
Pro
Sheet Author
Try giving your checkbox value=1, so <input type="checkbox" class="sheet-open" name="attr_torpedo_open" value="1" checked />
1541802701
G G
Pro
Sheet Author
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?
1541803051
Coal Powered Puppet
Pro
Sheet Author
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
G G
Pro
Sheet Author
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. 
1541803358
Coal Powered Puppet
Pro
Sheet Author
And now I know.
1541809826
Andreas J.
Pro
Sheet Author
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
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
LOL I totally understand...but you still thought of it. xD
1541853257
Jakob
Pro
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.
Pro
Sheet Author
API Scripter
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.
1541950195
Coal Powered Puppet
Pro
Sheet Author
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.