Problem/Motivation

Having a search block on every page is a very common use-case. However Drupal assigns an edit-submit id attribute to the button, and an edit-keys id attribute to the search input. That means we have a possibility to have a collision of duplicate ids on every page where we add a form apart from the search block form. That happens when this cached search block is rendered in a new context, because the search form is not processed to avoid id collisions, resulting in both forms having the edit-submit id attribute.

Providing unique IDs for this one form would substantially improve accessibility for most sites.

Steps to reproduce

- Enable caching
- Assign core search block to all pages
- As anonymous, visit a page without any forms other than search block
- Now, visit a page with search block and additional forms, e.g. login page

Proposed resolution

Just changing the IDs on the search form would fix this specific and common problem.
- Set a different id attribute on the submit button (other than edit-submit)
- Set a different id attribute on the input (other than edit-keys)

Issue fork drupal-3383541

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

juanolalla created an issue. See original summary.

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)

This looks like a duplicate of #1852090: Cached render elements can have duplicate HTML IDs. Can you confirm?

shivansunfire’s picture

It is not a duplicate of that issue.

The scope of the referenced issue you are asking about, is to discuss and find a solution to replace Drupal's prevention of id collision, on all forms. There is a tough debate going on about cache invalidation for form IDs, and no consensus has been reached yet, leading to a situation where this has been stuck for 11 years!

I have opened this issue specifically for the Search module, because here is where we are finding let's say 99% of the collisions, due to having a search block in every page is so common. So the goal of this issue is to provide a simple solution: change the ID just in this form. We have been forced to do that in alter hooks for 10+ years, so let's fix this now with specific IDs for the form Search module provides, while we keep the other issue open to continue discussing (it's been almost 1 year without movement there), and maybe one day we'll have a better cache solution or ID prevention globally.

cilefen’s picture

Status: Postponed (maintainer needs more info) » Active

shivansunfire’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

Seems to have caused some nightwatch failures.

Also think we will need our test showing this issue.

shivansunfire’s picture

It looks like the current solution is failing accessibility tests because when duplicating the block form on a page, elements get the same id. I've verified that Drupal's way of preventing duplicates id by adding dashes and numbers only works with "edit-keys" and "edit-submit", not other specific ids.

So we would need to add a different random hash / number to the id string.

smustgrave’s picture

shivansunfire’s picture

@smustgrave, no it doesn't look like it have anything to do with it.

liam morland made their first commit to this issue’s fork.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Needs work » Postponed

The Search Module was approved for removal in #3476883: [Policy, no patch] Move Search module to contrib .

This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

The deprecation work is in #3565780: [meta] Tasks to deprecate the Search module and the removal work in #3565783: [meta] Tasks to remove the Search module.

quietone’s picture

Project: Drupal core » Search (from core)
Version: main » 1.0.0
Component: search.module » Code
Status: Postponed » Needs work

The Search Module has moved from core to contrib,