The search field in the search block does not always use autocomplete="off"

Created on 8 August 2024, 8 months ago
Updated 22 August 2024, 8 months ago

I was looking at a documentation page on Firefox and I noticed that when I was searching for a function, I got two suggestions: one from Firefox and one from the site.

The dark box is the suggestion from the browser.
When I click on a suggestion given from the site, for example DRUPAL_BOOTSTRAP_FULL, the search box is filled with drupal_bootstrap, the suggestion given from Firefox, which is not what I want.

Looking at the HTML markup, this is what I see on Firefox.

<input class="api-search-keywords form-autocomplete form-text required ui-autocomplete-input" data-drupal-selector="edit-search" aria-describedby="edit-search--description" data-autocomplete-path="/api/search/autocomplete/11" type="text" id="edit-search" name="search" value="" size="60" maxlength="128" required="required" aria-required="true" data-once="autocomplete">

autocomplete="off" is missing, although that does not always happen. (I cannot predict when it is missing.)

With Edge, visiting https://api.drupal.org/api/drupal/includes%21cache-install.inc/class/Dru... (the page I was on when I noticed the issue with Firefox), autocomplete="off" is present, but I cannot say sometimes is present and sometimes not, like with Firefox.

The code adding the search box in that block is the following one. (Thanks goes to fjgarlin who pointed that out.)

    $form['search'] = [
      '#title' => $this->t('Function, class, file, topic, etc.'),
      '#title_display' => 'invisible',
      '#description' => $this->t('Partial match search is supported'),
      '#type' => 'textfield',
      '#default_value' => $query,
      '#required' => TRUE,
      '#attributes' => ['class' => ['api-search-keywords']],
      '#autocomplete_route_name' => 'api.search.autocomplete',
      '#autocomplete_route_parameters' => ['branch' => $branch->id()],
    ];
šŸ› Bug report
Status

Fixed

Version

2.0

Component

User interface

Created by

šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

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

Merge Requests

Comments & Activities

  • Issue created by @apaderno
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Status changed to Needs review 8 months ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Pipeline finished with Success
    8 months ago
    Total: 233s
    #247999
  • Status changed to RTBC 8 months ago
  • šŸ‡ŖšŸ‡øSpain fjgarlin

    I could reproduce this with Firefox as well, also via curl and with Chrome with Javascript disabled.

    I applied the fix locally and it works:

    āžœ  LOCAL PROJECT: 
    curl https://apidrupalorg.ddev.site/api/drupal/10.1.x | grep autocomplete=
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 41451    0 41451    0     0  65568      0 --:--:-- --:--:-- --:--:-- 65587
    <input class="api-search-keywords form-autocomplete form-text required" autocomplete="off" data-drupal-selector="edit-search" aria-describedby="edit-search--description" data-autocomplete-path="/api/search/autocomplete/10" type="text" id="edit-search" name="search" value="" size="60" maxlength="128" required="required" aria-required="true" />
    
    āžœ  REMOVE LIVE PROJECT
    curl https://api.drupal.org/api/drupal/11.x | grep autocomplete=
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 22435    0 22435    0     0  25444      0 --:--:-- --:--:-- --:--:-- 25436
    

    We can see results in the first but not the second, proving that the fix works. I'll merge it to the contrib project, but won't deploy until next week as we are undergoing some important changes today and I don't want to add any load to the infra team just in case.

    Thanks so much for the fix!!

  • Pipeline finished with Skipped
    8 months ago
    #248025
  • Status changed to Fixed 8 months ago
  • šŸ‡ŖšŸ‡øSpain fjgarlin

    Merged!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024