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)
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.

AttachmentSize
textarea-autocomplete.patch1.39 KB

#1

profix898 - October 20, 2006 - 15:18

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

kkaefer - October 20, 2006 - 17:36

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.

#3

profix898 - October 20, 2006 - 18:49

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 ;)

#4

Gerhard Killesreiter - October 20, 2006 - 21:13
Category:task» feature request

it's a feature.

#5

nedjo - January 5, 2007 - 06:42
Version:x.y.z» 6.x-dev
Status:patch (code needs review)» patch (code needs work)

Makes sense to me.

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

#6

catch - October 24, 2007 - 15:16
Version:6.x-dev» 7.x-dev

features go in the development version.

#7

Tobias Maier - November 18, 2007 - 13:44

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

#8

Tobias Maier - November 18, 2007 - 22:08
Status:patch (code needs work)» duplicate

#9

Tobias Maier - November 18, 2007 - 22:09
Status:duplicate» patch (code needs work)

sorry, was for a moment confused

#10

watcherFR - May 2, 2008 - 08:54

sub

 
 

Drupal is a registered trademark of Dries Buytaert.