Add autocompletion functionality to textareas
kkaefer - October 20, 2006 - 14:50
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | javascript |
| Category: | feature request |
| Priority: | normal |
| Assigned: | kkaefer |
| Status: | patch (code needs work) |
Jump to:
Description
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.
| Attachment | Size |
|---|---|
| textarea-autocomplete.patch | 1.39 KB |

#1
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.
#2
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 atextarea. The complete string (with the previous terms before the comma) is passed to a callback function, say"green, blue, ye". That string is thenexploded andtrimmed and a search on the last item is performed. Then, all elements areimploded with a completed last string. and displayed. That means, it’s something the server should care of, not the client.#3
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
which all should be done with the next release. But thats only my opinion ;)
#4
it's a feature.
#5
Makes sense to me.
For consistency, need to add
'#autocomplete_path' => FALSEto 'textarea' insystem_elements().#6
features go in the development version.
#7
closed dupe of this issue:
http://drupal.org/node/98500
#8
#9
sorry, was for a moment confused
#10
sub