Do not use label HTML tag in "item" form element

Created on 18 September 2019, almost 6 years ago
Updated 30 January 2023, over 2 years ago

Consider this form element.

$form['example'] = [
  '#type' => 'item',
  '#title' => $this->t('Example title'),
  '#markup' => $this->t('Example value'),
];

When rendered it produces the following markup:

<div id="edit-example" class="js-form-item form-item js-form-type-item form-type-item js-form-item-example form-item-example">
  <label for="edit-example">Example title</label>
  Example value
</div>

As stated in the Mozilla documentation:
for attribute contains the id of a "labelable" form-related element in the same document as the <label> element.

In this case <div> is used which is certainly not a "labelable" form-related element.

The relevant question on SO.
https://stackoverflow.com/questions/12195052/is-it-allowed-to-use-label-...

🐛 Bug report
Status

Needs work

Version

10.1

Component
Form 

Last updated about 2 hours ago

Created by

🇷🇺Russia Chi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024