$element['#id'] should respect $element['#attributes']['id'] if it's set, since that is often used to specify the HTML ID

Created on 11 July 2012, over 12 years ago
Updated 30 January 2023, almost 2 years ago

it is possible to change the form element id through #attributes, but the label does not respect that.

example:
form element:

  $form['test'] = array(
    '#title' => 'Test',
    '#type' => 'checkbox',
    '#attributes' => array('id' => 'my-checkbox'),
  );

rendered:

  <input type="checkbox" class="form-checkbox" value="1" name="test" id="my-checkbox">
  <label for="edit-test" class="option">Test </label>

problem:
Info: reference to non-existent ID "edit-test"

possible solution:
this code needs to be improved in form.inc

function theme_form_element_label() {
  ...
  if (!empty($element['#id'])) {
    $attributes['for'] = $element['#id'];
  }
  ...
πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
FormΒ  β†’

Last updated about 22 hours ago

Created by

πŸ‡­πŸ‡ΊHungary pasqualle πŸ‡­πŸ‡Ί Budapest

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.71.5 2024