Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently, only textfields can be autocomplete fields. But I see no reasons why we can’t use textarea
s as well. This patch adds the autocompletion feature to textarea
s. This can for example be useful if you want to specify a list of users - a textfield is too small for that.
Comment | File | Size | Author |
---|---|---|---|
#25 | 1.png | 9.26 KB | Jarviss |
#20 | 0002-Issue-90329-by-ericduran-Added-autocompletion-function.patch | 1.61 KB | bryanhirsch |
#18 | 0001-Issue-90329-by-ericduran-Added-autocompletion-functi.patch | 1.97 KB | ericduran |
#14 | 90329.patch | 1.12 KB | ericduran |
textarea-autocomplete.patch | 1.39 KB | kkaefer | |
Comments
Comment #1
profix898 CreditAttribution: profix898 commentedI 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.
Comment #2
kkaefer CreditAttribution: kkaefer commentedYes, 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 thenexplode
d andtrim
med and a search on the last item is performed. Then, all elements areimplode
d with a completed last string. and displayed. That means, it’s something the server should care of, not the client.Comment #3
profix898 CreditAttribution: profix898 commentedThe 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 ;)
Comment #4
Gerhard Killesreiter CreditAttribution: Gerhard Killesreiter commentedit's a feature.
Comment #5
nedjoMakes sense to me.
For consistency, need to add
'#autocomplete_path' => FALSE
to 'textarea' insystem_elements()
.Comment #6
catchfeatures go in the development version.
Comment #7
Tobias Maier CreditAttribution: Tobias Maier commentedclosed dupe of this issue:
http://drupal.org/node/98500
Comment #8
Tobias Maier CreditAttribution: Tobias Maier commentedComment #9
Tobias Maier CreditAttribution: Tobias Maier commentedsorry, was for a moment confused
Comment #10
PGiro CreditAttribution: PGiro commentedsub
Comment #11
Dave ReidPlease be sure to add menu access checking to the autocomplete path like in theme_textfield.
Comment #12
smitty CreditAttribution: smitty commentedI 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."
Comment #13
sun.core CreditAttribution: sun.core commentedComment #14
ericduran CreditAttribution: ericduran commentedHere's a patch against d8.
I didn't actually test this, but adding a couple of test couldn't hurt.
Comment #15
ericduran CreditAttribution: ericduran commentedComment #17
ericduran CreditAttribution: ericduran commentedAh, I forgot to add the #autocomplete property to the textarea
Comment #18
ericduran CreditAttribution: ericduran commentedLets see if the bot can apply git format-patch patches.
Comment #19
ericduran CreditAttribution: ericduran commentedComment #20
bryanhirsch CreditAttribution: bryanhirsch commentedRe-rolled by the Boston Initiative. This applies cleanly as of commit 718fe5d90770f36335053d6f92fc53f73ac95951.
Comment #21
nagiek CreditAttribution: nagiek commentedWould this be backported to D7?
Comment #22
ericduran CreditAttribution: ericduran commented@nagiek, most likely note, being that is a branch new feature request.
Comment #23
Jarviss CreditAttribution: Jarviss commentedWhat about Drupal 7 Textarea Autocomplete! such field widget can be used for content tags, a textarea with autocomplete!
Comment #24
arosboro CreditAttribution: arosboro commentedIf 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.
Comment #25
Jarviss CreditAttribution: Jarviss commentedI 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.
Also as autocomplete I get:
tag (1729), tag (1728)
May it be simple as usual: tag1, tag 2, tag 3
Comment #26
andypostProbbaly this issue will need a re-roll after #675446: Use jQuery UI Autocomplete
Comment #29
droplet CreditAttribution: droplet commentedA bit crazy idea. I think it should be done in Contrib. Welcome to re-open.