question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checkbox (hidden field) causing CSS problem

See original GitHub issue

We are using a template that allows for styled checkboxes. The problem occurs when we render the checkbox. It puts a hidden field before the required <label> tag. If the <label> tag does not come directly after the checkbox it will fail to render.

This is the hidden field the code is adding… <input name="EnableAD" type="hidden" value="false">

This is the non-working result. The hidden input field is rendered before our lablel tag causing it to fail.

<label class="checkbox" for="EnableAD"><input checked="checked" class="ace-switch ace-switch-7" data-val="true" data-val-required="The EnableAD field is required." id="EnableAD" name="EnableAD" type="checkbox" value="true" /> <input name="EnableAD" type="hidden" value="false" /> <span class="required">Enable</span></label>

This is a working result (trying to achieve this output). Notice the hidden input field is not in the label tag.

<label class="checkbox" for="EnableAD"><input checked="checked" class="ace-switch ace-switch-7" data-val="true" data-val-required="The EnableAD field is required." id="EnableAD" name="EnableAD" type="checkbox" value="true" /> <span class="required">Enable</span></label> <input name="EnableAD" type="hidden" value="false" />

So, what we need to find out is how to render or remove the hidden field so our label shows first instead. Any ideas?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alihassanm62commented, Jul 31, 2019

@DmitryEfimenko described the solution so well. I’m not using Ace template. But I got the same issue. Just changing + to ~ solved my problem. You guys are superb.

.checkbox-success input[type=checkbox]:checked ~ label::before {
    background-color: #1abc9c;
    border-color: #1abc9c;
}

.checkbox-success input[type=checkbox]:checked ~ label::after {
    border-color: #fff !important;
}

.checkbox input[type=checkbox]:checked ~ label::after {
    content: "";
    position: absolute;
    top: 6px;
    left: 7px;
    display: table;
    width: 4px;
    height: 8px;
    border: 2px solid #adb5bd;
    border-top-width: 0;
    border-left-width: 0;
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg)
}
0reactions
electricmessiahcommented, Jul 19, 2013

The Ace template isn’t free. The fix itself doesn’t involve the code in this repo. If others run into this issue, finding this thread and knowing that the fix lies in the LESS files should provide all the info they need. This little snip might be of use too.

$(function(){
  $('input[type=checkbox],input[type=radio]').after('<span class="lbl" />');
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

why is Html.CheckBox generating an additional hidden input
The hidden input was causing problems with styled checkboxes. So I created a Html Helper Extension to place the hidden input outside the...
Read more >
Checkbox hack and hiding the input element - HTML & CSS
The checkbox hack is inherently inaccessible to keyboard users because its not clear that you are navigating a form field which doesn't work ......
Read more >
Remove additional spacing from hidden fields on a form
I'm struggling with how to remove extra spaces being left on a form form hidden fields. It seems to be happening with both...
Read more >
<input type="checkbox"> - HTML: HyperText Markup Language
Note: If a checkbox is unchecked when its form is submitted, neither the name nor the value is submitted to the server. There...
Read more >
Problem Solved: Custom Checkbox not Working on Edge
There is an easy solution, add a hidden field with unselected value, for example, 0 or False. The name of the field should...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found