Fields that make use of 'user/autocomplete' as their #autocomplete_path no longer work in 7.39.

This bug in contrib might offer some clues: https://www.drupal.org/node/2556749

In firebug I am seeing "TypeError: $input[0] is undefined" when the page containing my form first loads.

I'm seeing this in a custom module whose autocomplete fields worked fine for a year or so prior to the 7.39 release. Here is an example of a form field that no longer works...

$form['student'] = array(
      '#title' => t('Student'),
      '#type' => 'textfield',
      '#size' => '20',
      '#autocomplete_path' => 'user/autocomplete',
      '#attributes' => array('id' => 'tutoring-student', 'placeholder' => t('Username')),
      '#required' => TRUE,
      '#default_value' => isset($tutoring->student) ? $tutoring->student : NULL,
      '#weight' => -8,
    );

Comments

arnoldbird created an issue. See original summary.

cilefen’s picture

This issue is a duplicate of #2556749: Autocomplete not working in contrib, which is evidently, not "fixed".

hutch’s picture

In the example code above, try changing the "id" for a "class" in the '#attributes' array. You may need to change code elsewhere to accommodate. As far as I can tell Drupal-7.39 no longer tolerates more than 1 id on a form element and the automatically generated id is the one it cannot find, eg probably something like "edit-student"

David_Rothstein’s picture

      '#attributes' => array('id' => 'tutoring-student', 'placeholder' => t('Username')),

Try setting the ID using the '#id' property instead of (or maybe in addition to) the above. That's the correct way to specify a specific ID in the form API. See:

https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h...
https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h...
#2554857: Add item autocomplete not working after update to Drupal 7.39

arnoldbird’s picture

Status: Active » Closed (works as designed)

Thanks @hutch and @David_Rothstein -- changing the ID to a class, so Drupal can use the default ID, fixed this for me. I'm not sure why I set an ID in the first place. Somehow prior to 7.39 it didn't matter.