Hi Drupal Core, here's a suggestion for better user functionality.

Summary

  1. Turn the return value of autocomplete.js into an array.
  2. When selected, autocomplete.js fills in the textfield with the value of the array_key instead of the full array.
  3. The array_key would be specified in the feeding function value.

Where would we use this?

User autocomplete with pictures.

Description

Autocomplete works on strings. Find a string, make an array with strings, return the strings. This seems pretty limited for user experience. We would have to change code like this.input.value = $(node).data('autocompleteValue'); to look for the main field. The HTML would have to be structured too.

In a perfect world, we could do this in D7. If there's no "main-field" specified, return to normal behaviour.

Sample HTML return

(not including the ARIA)

  <div id='autocomplete'>
      <div id='autocomplete-0' class= 'autocompleteValue'>
        <div class="field-0">AAA</div>
        <div class="field-1 main-field">AAA</div>
        <div class="field-2">AAA</div>
      </div>
      <div id='autocomplete-1' class= 'autocompleteValue'>
        <div class="field-0">BBB</div>
        <div class="field-1 main-field">BBB</div>
        <div class="field-2">BBB</div>
      </div>
  </div>

What do you think?

Comments

nagiek’s picture

I had something like this in mind...

    var result = $(this.selected).data('autocompleteValue');
    var output = result;
    if (result.indexOf("<span>") > 0 && result.indexOf("</span>") > 0) {
      var start = result.indexOf("<span>") + 6;
      var end = result.indexOf("</span>");
      output = result.substring(start, end);
    }
    this.input.value = output;
Everett Zufelt’s picture

nagiek’s picture

Status: Active » Closed (duplicate)

can't wait.

nagiek’s picture

Title: Switch autocomplete.js from string-based to array-based » Add support for formatResult, formatItem and formatMatch in autocomplete.js
Version: 7.x-dev » 8.x-dev
Status: Closed (duplicate) » Postponed (maintainer needs more info)
nagiek’s picture

Status: Postponed (maintainer needs more info) » Postponed
nod_’s picture

Status: Postponed » Closed (won't fix)

Since we'll just go ui autocomplete anyway.