Message field id attr not guaranteed to match label for attr

Created on 12 June 2025, 19 days ago

Problem/Motivation

This is another instance of 3520541 🐛 Interaction/submission issues Active where Drupal changes id attributes in forms. In this instance it's because the form plugin manually sets the textfield's id attribute, but not the label's for attribute.

This results in a11y audits reporting no text label for the form field (i.e. because the two attributes must match).

Steps to reproduce

Trigger Drupal into modifying the id attributes of the form (I'm not sure what specific circumstances trigger this, but it always happens in certain themes).

Proposed resolution

The simplest fix would have been to explicitly set the for attribute on the form label.

However, testing shows Drupal still overrides it. So, absent that option, the solution turns out to be to let Drupal have its way with the field's id attribute and the label's for attribute. When we do this, everything continues working as intended since Drupal evidently doesn't care about the label's id attribute.

Remaining tasks

Merge request.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France bedlam Lyon

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024