Is there a way to have the drupal autocomplete feature on a CCK textfield?

Comments

yched’s picture

Title: ajax autocomplete » autocomplete for text field
Component: General » text.module
Category: support » feature

it is not built in. What do you want to complete with ? existing values for the field ?
I guess it's a feature request...

But you can also come with a form_alter in a custom module of yours, and specify your own '#autocomplete' path.
See Form API documentation about that.

fago’s picture

I think there's already an autocomplete widget in the CCK taxonomy module (content_taxonomy). Perhaps this one should be adapted to be generic, so that it works with text fields too.

lefnire’s picture

bump, this should be implemented.

cgjohnson’s picture

I second that!

moshe weitzman’s picture

Title: autocomplete for text field » autocomplete for text field. Make suggestions like free tagging.

Good idea to use existing values as suggestions in autocomplete.

FiReaNGeL’s picture

I can say that this would have been a nice feature to have; I don't know about the inner workings of CCK, but I think this would be relatively easy to implement.

SamRose’s picture

In reply to number 2 above, I am looking into doing this now...

brunodbo’s picture

Jeremy Toaster’s picture

Version: 5.x-1.4 » 6.x-2.x-dev

That module is only for 5.x-1.x-dev

I run a record label site in which people enter their bands concert dates. Either having Auto complete or a way to store venue information and have it populate the fields upon selection with auto complete would be wonderful to have in 6.x and up.

jeremy

gagarine’s picture

track

SamRose’s picture

profix898’s picture

Any news here? I'm also hoping for a textfield with autocompletion from previous entered values.

Coupon Code Swap’s picture

Subscribing

Apollo610’s picture

I would also be interested in some sort of autocomplete implementation into CCK as well.

In my use case, it would essentially take the place of ridiculously long select-lists (one of my lists could potentially be over 300 rows, not very friendly for users to have to scroll through). So as long as we could enter values when creating the field similar to how select lists are currently handled (or be able to point to a drupal table/field), I think this would be perfect in CCK.

Thanks!

yched’s picture

We could add options to the textfield widget :
- no autocomplete (current behavior)
- autocomplete, fetch values from the list of allowed values
- autocomplete, fetch values from the existing values in the field.

I don't intend to work on this myself in a near future, but patches are welcome. Shouldn't be *too* hard...

vacilando’s picture

I support this idea a lot.

aleagi’s picture

Hi,

It will be really great to have this options on textfields! @:)

Good work on that guys!

patchak’s picture

I offer to sponsor 150$ for this. Please contact me if you are ready to provide a good working patch to provide this functionnality!!! thanks a lot!!

Patchak

markus_petrux’s picture

There's a module for Drupal 5 that seems to do this. I'll try to contact the author (linuxbox). If he's not up for porting the module to Drupal 6, then I'll ask him to transfer maintainership of the module, so I can do it.

In any case, if linuxbox does not respond soon, I can do this anyway and post it in the textfield_autocomplete issues queue.

patchak’s picture

Markus : cool! Thanks for the message and let me know how it goes!

zmove’s picture

/subscribe to the idea

marcvangend’s picture

subscribe, this would be a great feature.

markus_petrux’s picture

I have written this as a contrib module that's on my sandbox now, temporarily. I posted about it here:

http://drupal.org/node/281885#comment-1233218

@KarenS/yched: could you please take a look at the code and see if it worths for CCK, or otherwise it is jusy fine as a contrib module? Thank you so much.

The code can be found here:
http://cvs.drupal.org/viewvc.py/drupal/contributions/sandbox/markus_petr...

If it has to live as a contrib, the I guess this issue could be closed.

karens’s picture

This looks very interesting. yched, what do you think? It might also be something to push into the D7 fields as a generic field.

markus_petrux’s picture

I was about to create a new module named autocomplete_widgets, as it would complement optionwidgets currently in CCK. I may wait a little if you feel this could integrated into CCK itself.

yched’s picture

+1 on the principle, a few remarks from a cursory look :

- Markus, not sure why you chose to write this as two separate widgets instead of one widget with a setting ?
- The code looks like it would be not that many lines if merged with the current text.module
- But then that code would need to be duplicated if we wanted the same feature on number fields. Maybe we can live with that.

Not much more articulate thoughts at this time of the day :-)

markus_petrux’s picture

Markus, not sure why you chose to write this as two separate widgets instead of one widget with a setting ?

Because one of the widgets (the one based on allowed values list) applies to both text and number fields, but the other (the one that takes candidates from existing field's data) applies only to text fields.

IMHO, it is necessary this feature for number fields. You may have a list of allowed values, but need numbers in the DB. I hope that makes sense.

There are 2 things I'm not happy with:

1) What happens if the user changes the widget type when the field has already data in it. Should this be allowed in all cases?
2) The name of the widgets: Autocomplete text field (limited) -vs- Autocomplete text field (unlimited) ¿?

Edited: As per the name of the module, since we already have "Option Widgets", I would suggest here "Autocomplete widgets".

marcvangend’s picture

I just noticed that archard has recently published a module for this: http://drupal.org/project/cck_autocomplete. I didn't try it yet, but it might be a good starting point.

Just a thought:
An autocomplete textfield needs a datasource (defined as the #autocomplete_path value, http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...). A sensible default would be to autocomplete existing values for that field, but it would be great if we can allow a custom datasource. The simple way would be a setting where you can enter the custom autocomplete path. But maybe it would me much nicer to create a new hook (hook_autocomplete?) so modules can publish an autocomplete data source by implementing this hook.

markus_petrux’s picture

In the module I did, you can choose the widget that takes candidates from Allowed values list, and there you can use a custom PHP function to generate the values dynamically. ;-)

marcvangend’s picture

Of course! I don't know why I forgot that you can use php to load allowed values...

Still, it wouldn't be very efficient when you combine it with functions that already generate autocomplete values. Take user_autocomplete() for instance: it returns a JSON object. The allowed values PHP would have to convert this into an array, only to be turned into JSON object again by your module...

markus_petrux’s picture

@marcvangend #30: Well, if I was to release this as a module, then I wouldn't evaluate feature requests until then.

@KarenS/yched: Could you please review comment #27 above? I'm interested to know if you would include this in CCK itseld, otherwise I would create a separate project. Please, let me know if you wish anything changed, or if you wish a patch, etc. I would really be glad to work on it until it's done. :)

markus_petrux’s picture

Status: Active » Fixed

Well, I ended up creating a separate project for feature. It can be found here:

http://drupal.org/project/autocomplete_widgets

Cheers

marcvangend’s picture

Thanks Markus, I'll give it a spin soon.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

off’s picture

Any solution for drupal 7?