I am trying to make a on/off button for a form. The button's style depends on the checkbox's value (checked/not-checked) and the checkbox itself is hidden. I know you can use css to govern the style (like the label button's colour). Is there any way I can also change its parents' style?
HAML (RoR):
%label.primary_btn
set as primary
= f.check_box :is_on, style: 'display:none;'
HTML:
<label class="primary_btn">
On/Off Button
<input name="post[images_attributes][0][is_on]" type="hidden" value="0"><input id="post_images_attributes_0_is_on" style="display:none;" type="checkbox" value="1">
</label>
CSS:
.primary_btn {
float: left;
clear: both;
padding: 6px 10px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
border-bottom-right-radius: 9px;
border-bottom-left-radius: 9px;
color: white;
box-shadow: black 0px 1px 4px -1px;
cursor: pointer;
background-color: #6d6d6d;
}
Addition comment:
I can't use 'for' in label because I cannot call the id
of the nested field :is_on
. Thanks!