Render regular element in a form should not duplicate container ID.

Created on 29 September 2014, over 9 years ago
Updated 8 March 2024, 4 months ago

Problem/Motivation

Regular elements constructed in buildForm() render with an ID. Also, the container gets the same ID. So, the page has two elements with the same ID.

Example:

<?php
$form['system_compact_link'] = array(
  '#type' => 'system_compact_link',
}
?>

We were able to work around this in the linked issue by adding:

<?php
'#id' => FALSE,
?>

Proposed resolution

Do not add an ID attribute to an element that already has a container with the same ID.

Remaining tasks

First of all, should Form building allow non-form types? or, is this change actually needed?
Write a test.
Decide on how to fix it. If going with the current solution, fix remaining test fail.

Original report by @lokapujya

Follow-up to #1833932: Convert theme_system_compact_link() into a #type link

🐛 Bug report
Status

Closed: cannot reproduce

Version

11.0 🔥

Component
Theme 

Last updated 1 minute ago

Created by

🇺🇸United States lokapujya Boston

Live updates comments and jobs are added and updated live.
  • 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.

  • I've just attempted to replicate this on 10.2.4

    I created a custom module using drush generate simple:form and installed

    In the form I created the following insight the generated buildForm method

        $form['acontainer'] = [
    	    '#type' => 'container',
    	    '#title' => $this->t('Container'),
        ];
    
        $form['container']['atextfield'] = [
    	    '#type' => 'textarea',
    	    '#title' => 'one',
    	    '#required' => TRUE,
        ];
    
    

    When I inspect the elements on the page rendered I see a control with an id 'edit-atextfield' which has a wrapper div with id 'edit-acontainer'

    If this doesn't demonstrate the problem please include some clear steps to reproduce.

Production build 0.69.0 2024