Currently, only textfields can be autocomplete fields. But I see no reasons why we can’t use textareas as well. This patch adds the autocompletion feature to textareas. This can for example be useful if you want to specify a list of users - a textfield is too small for that.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

profix898’s picture

I cant see any benefit from this patch. The current implementation always sends the whole content of a textfield to the #autocomplete_path callback function AFAIK and gets a list of similar strings in response. This is good enough to enter/autocomplete a username or a path. Your patch adds the same functionality to textareas, but you still can't enter a list of users, right?

If you would extend the javascript to extract only the last word, send it back to the callback and replace it with the user's selection from
the resulting dropdown, it would be really helpful and we could even provide autocomplete from a dictionary or stg for textareas. With such
modification you could also enter a list of users into a textfield.

kkaefer’s picture

Yes, this patch does not have direct benefits. The reason I made this patch is because I needed this patch for a module (which has a “recipients” field that can be filled with users and/or e-mail addresses).

Currently taxonomy.module, which allows the user to enter taxonomy terms in a text field separated by commas, uses the same mechanism, just with a text field instead of a textarea. The complete string (with the previous terms before the comma) is passed to a callback function, say "green, blue, ye". That string is then exploded and trimmed and a search on the last item is performed. Then, all elements are imploded with a completed last string. and displayed. That means, it’s something the server should care of, not the client.

profix898’s picture

The current implementation of autocompletion in Drupal uses GET method and appends the search string to the url. By doing this we are limited to about 2000 characters (http://www.boutell.com/newfaq/misc/urllength.html). I dont think you will reach this limit with a textfield, but its easy with a textarea. You could argue that autocomplete should be used only to enter users/pathes/taxonomy term. But if we offer this feature for textareas in core, it implies to work in all common cases. One method to ensure this, is to add some basic logic to the client side (extract the last word in js) or use a different method (POST?).
You can still provide a simple autocomplete for textareas in your module by creating a custom form element type.

I'm all for autocomplete in textareas, but

  1. its a feature request (not a task)
  2. it must be considered carefully and
  3. might need some changes to js and autocomplete callbacks

which all should be done with the next release. But thats only my opinion ;)

Gerhard Killesreiter’s picture

Category: task » feature

it's a feature.

nedjo’s picture

Version: x.y.z » 6.x-dev
Status: Needs review » Needs work

Makes sense to me.

For consistency, need to add '#autocomplete_path' => FALSE to 'textarea' in system_elements().

catch’s picture

Version: 6.x-dev » 7.x-dev

features go in the development version.

Tobias Maier’s picture

closed dupe of this issue:
http://drupal.org/node/98500

Tobias Maier’s picture

Status: Needs work » Closed (duplicate)
Tobias Maier’s picture

Status: Closed (duplicate) » Needs work

sorry, was for a moment confused

PGiro’s picture

sub

Dave Reid’s picture

Please be sure to add menu access checking to the autocomplete path like in theme_textfield.

smitty’s picture

I tried this patch in D5 and it works quite fine.

But every time a user hits the enter-key (to get a new line in the textbox - so the autocomplete-box is empty) and then hits any other key (to write something) there is an error: "An HTTP error 404 occured."

sun.core’s picture

Version: 7.x-dev » 8.x-dev
ericduran’s picture

Assigned: kkaefer » ericduran
FileSize
1.12 KB

Here's a patch against d8.

I didn't actually test this, but adding a couple of test couldn't hurt.

ericduran’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 90329.patch, failed testing.

ericduran’s picture

Ah, I forgot to add the #autocomplete property to the textarea

ericduran’s picture

Lets see if the bot can apply git format-patch patches.

ericduran’s picture

Status: Needs work » Needs review
bryanhirsch’s picture

Re-rolled by the Boston Initiative. This applies cleanly as of commit 718fe5d90770f36335053d6f92fc53f73ac95951.

nagiek’s picture

Would this be backported to D7?

ericduran’s picture

@nagiek, most likely note, being that is a branch new feature request.

Jarviss’s picture

What about Drupal 7 Textarea Autocomplete! such field widget can be used for content tags, a textarea with autocomplete!

arosboro’s picture

If you apply the patch in #20 by hand, it works without modification for 7.0 and 7.12. I'll write a patch eventually against D7.

Jarviss’s picture

FileSize
9.26 KB

I applied patch #20 on drupal 7.12 and I get Entity Reference field but still I don't see how to use Textarea autocomplete, I get only input autocomlete?
And I see no difference between Autocomplete widget and Autocomplete (tags style) because in result I get the same input single line autocomplete.

example

Also as autocomplete I get:
tag (1729), tag (1728)

May it be simple as usual: tag1, tag 2, tag 3

andypost’s picture

Probbaly this issue will need a re-roll after #675446: Use jQuery UI Autocomplete

Status: Needs review » Needs work
droplet’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Needs work » Closed (won't fix)
Issue tags: +ux

A bit crazy idea. I think it should be done in Contrib. Welcome to re-open.