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.

Form checkboxes not working properly with htmlfor attribute

See original GitHub issue

There are cases where DOM is dynamically generated or parsed as it happens in React or when using composable DOM elements libraries as bel.

Where this case

`<form action="#">
    <p>
      <input type="checkbox" id="test5" />
      <label for="test5">Red</label>
    </p>
  </form>
`

is parsed as

<form action="#">
    <p>
      <input type="checkbox" id="test5" />
      <label htmlfor="test5">Red</label>
    </p>
</form>

this changes for attribute to htmlfor according to W3C Recommendation and getting checkbox controls not working properly.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
fegacommented, Apr 19, 2017

Closed due inactivity, feel free to reopen it if it is still necessary, in that case, please provide a way to reproduce it. like a codepen.

0reactions
stef-kcommented, Aug 24, 2016

I have the same issue with Django template, using the following code:

<p>
    <label for="{{ form.remember.id_for_label }}">{% trans "Remember Me" %}:</label>
    <input type="checkbox"
           name="{{ form.remember.html_name }}"
           id="{{ form.remember.id_for_label }}"/>
</p>

The checkbox and the respective label are rendering behind the submit button as seen bellow

selection_002

The following works

    <p>
      <input type="checkbox" id="test5" />
      <label for="test5">Red</label>
    </p>

Maybe it has something to do with the dynamic generated parts of the widgets?

Read more comments on GitHub >

github_iconTop Results From Across the Web

label not working with checkbox - Stack Overflow
I believe the label element links to the id attribute, not the name attribute. Try this: <form> <input type="checkbox" name="showRatings" id="showRatings" ...
Read more >
<input type="checkbox"> - HTML: HyperText Markup Language
A Boolean attribute indicating whether this checkbox is checked by default (when the page loads). It does not indicate whether this checkbox is ......
Read more >
HTML: Validating a checkbox with HTML5 - The Art of Web
While HTML5 form validation is typically about missing or invalid text inputs, there are other form element types that also require attention.
Read more >
Handling Checkbox Data With In HTML: Here's How »
The <label> should always use for attribute, which specifies that it is connected to the <input> by id . This is an important...
Read more >
HTML DOM Input Checkbox Object - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP,...
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