I'm using some CSS form elements that use :checked styling, such as.
input:checked + label {
background-color: green;
}
Where the corresponding HTML (simplified for example) would be:
<input type="checkbox">
<label>My Checkbox</label>
Unfortunately, :checked styling wreaks havoc when .field_with_errors comes into play, because it creates a div around both elements, like so:
<div class="field_with_errors">
<input type="checkbox">
</div>
<div class="field_with_errors">
<label>My Checkbox</label>
</div>
As far as I know, given that HTML structure it's no longer possible to style the label based on whether the checkbox is checked.
I can't entirely remove field_with_errors
on either labels or inputs, because legacy aspects of the application I'm working on rely on it.
So I'm wondering if it is possible to simply make it so that field_with_errors
doesn't wrap elements if they are hidden. I don't know a ton about Ruby/Rails yet, but I know (of course) that it runs pre-page-load. I'm still hoping beyond hope that maybe I'm not thinking of something :-D.
Any alternative but similarly-effective approaches are also welcome.