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 Input elements are inside the Label elements

See original GitHub issue

General information

Checkbox Input elements (both with schema elements and when choosing Properties) are generated inside the Label elements, and not after/before them as it’s normally done. This is bad semantics and produces problems when your styling relies on this fact.

  • json-editor version:1.3.5

Expected behavior

Normally a label and its input element are placed next to each other as it can be seen here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox.

Actual behavior

This is what ends up getting generated in for example https://json-editor.github.io/json-editor/: <label class="checkbox" style="display: inline-block; font-weight: normal;"> age <input type="checkbox" disabled="" style="width: auto; display: inline-block;"> </label>

Steps to reproduce the behavior

Just check the HTML code produced.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
pmk65commented, Apr 27, 2019

Are there other CSS frameworks which require the label before or after? Should/could the theme handle it?

The Materialize Theme set the for attribute on the label tag in the function getFormControl But it still wraps the input tag inside the label tag, which is correct according to the Materialize documentation,

Personally I always use the wrap method, as you don’t have to worry about id and for attributes. (less code.)

1reaction
pmk65commented, Apr 26, 2019

From w3: The label itself may be positioned before, after or around the associated control. Either one is valid. Wrapping the label tag around the input tag allows you to skip the for attribute on the label tag and the id on the input tag,

Read more comments on GitHub >

github_iconTop Results From Across the Web

<input type="checkbox"> - HTML: HyperText Markup Language
A checkbox allows you to select single values for submission in a form (or ... <input> elements of type checkbox are rendered by...
Read more >
checkboxes inside labels? - Stack Overflow
Labels may contain inline elements (except other labels). Input elements are inline elements. imho below: Anyhow, I would not put the checkbox ......
Read more >
Input checkboxes wrapped inside <labels> - UX Stack Exchange
Wrap the label around the checkbox. This makes it much easier to click the button. If the label is separate from the control,...
Read more >
Using label elements to associate text labels with form controls
The objective of this technique is to use the label element to explicitly associate a form control with a label. A label is...
Read more >
Need help with each checkbox nested in its own label element
am kinda stuck somewhere here…its requesting me to nest my checkboxes in their individual label elements which I think I have already done ......
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