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.

problem ith checkboxes & radios when <label> is before the <input>

See original GitHub issue

the elements only work if out HTML looks like this:

<form>
  <input>
  <label></label>
</form>

However usually we see CMSs and apps using a structure like this:

<form>
  <label></label>
  <input>
</form>

or even this:

<form>
  <label>
    <input>
  </label>
</form>

Currently these elements only work in Materialize if the <label> element is after the <input>

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

3reactions
gvankeerberghencommented, Jul 31, 2016

This slightly more robust version of @erichschroeter’s workaround did the trick for me:

$.each($(':checkbox'), function(k, v) { var label = $('label[for="' + this.id + '"]'); $(this).insertBefore(label); });

2reactions
erichschroetercommented, Oct 26, 2015

Well, for those that come across this still wondering if there’s a workaround, I think I found one. Just include jquery and include the following snippet.

<script>
/* Fix bug where materializecss checkboxes only render if before labels. */
$.each($(':checkbox'), function(k, v) {
    var label = $(this).closest('label');
    $(this).insertBefore(label);
});
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS checkboxes & radio buttons when input is inside label?
I already have my sprite ready to go, I just need to figure the CSS out. My main issue is I can't figure...
Read more >
Problem with my checkbox and radio buttons on survey form
Hi I don't understand why my checkboxes and radio buttons are not BEFORE their label on the web form and I don't understand...
Read more >
Separate label and input for checkboxes/radios #22738 - GitHub
I need to separate a checkboxes label and input to conform with django forms. There's a similar issue #19095 where @patrickhlauke mentioned ...
Read more >
Accessibility issues of checkboxes and radio buttons
Accessibility issues of checkboxes and radio buttons. This document discusses how to change a checkbox or radio button setting by using keyboard only, ......
Read more >
Tabbing through form never gives focus to radio buttons or c
Hello, I'm having an issue where when I have either radio buttons or checkboxes on a form in Angular they never gain focus...
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