By slovan-mooney on
Hello,
I have 2 content types (event, venue). The content type event has a cck node reference to venue.
Now I have created a view with an exposed filter "node reference venue". Thereby a user can select a venue. As result he gets its events. That works. My problem is, that the selection is offered by a multi select list. Instead I would like to have the nice autocomplete text field.
Therefore my question:
How can I replace in an exposed filter the multi select list by the autocomplete text field??
Thx!!!
Comments
Hi slovan, I faced your
Hi slovan,
I faced your problem before, I had two content types (contact, organization). the content type contact has a node reference to an organization. I've created a view to list contacts which exposes an organization filter so I can filter contacts by their organization. I managed to convert organization select list to an autocomplete textfield using the following humble approach:-
1-Modify the select list:
2- Create menu item
3-Create the callback:
after this step assure that your cache are clear.
4-The contacts view used to filter contacts according to organization nid, however, our handler method that returns organization matches, returns organization titles. so, in views_query_later hook we have to replace the supplied organization title with organization nid:
If you followed this approach your autocomplete textfield should be workin, however, i assure that there is a better approach out there, if you found one, please inform us.
Hope this would be helpful.
I have the same problem
I have the same problem.
Instead of "contact" content type I have "article" one,
instead of "organization" contenet type I have "author".
First step: In views.module I' ve found function views_form_alter and changed it:
And, really, I saw the result - the type of widget was changed to autocomplete text field.
Than I've taken the second step changing the function views_menu in views.module:
Now when I am trying to input something in my autocomplete field for authors I get a 404 mistake: http://mysite/author/autocomplete not found.
What should I do to fix it?
1- You should NEVER modify
1- You should NEVER modify core or contrib modules, the changes that you have made to views.module could be inserted in form_alter of any other module of yours. SO, if you have no modules of yours, you could create a new module and supposed that it's name is [xmodule.module],
you would define a form_alter function like this:
2- I think that the menu item you have added is ok, but, I'd like you to be informed that the callback (author_autocomplete) should be defined in your module, this function will be resposible for retrieving the values that matches textfield's input.
3- From your code I think that you want to fill the autocomplete field with author names, so your callback could be like this:
4-The articles view is used to filter articles according to authors nid, however, our handler method that returns authors matches, returns authors titles. so, in views_query_later hook we have to replace the supplied author's title with author's nid:
Hope this would be helpful.
Thanks a lot, Raemon, maybe some ideas for debug?
Thanks a lot, Raemon for your help,
now I've done all in a separate module named views_filter_autocomplete.module.
My code is:
Now I have no mistake messages, but my autocomplete list is empty (after text input it tryes to load data).
I've tried to debug sql-queries in phpmysql and I've got a right list of author names.
Maybe you have some ideas for debuging?
#sorry, I cant delete this empty post
#sorry, I cant delete this empty post
Maybe you should just clear
Maybe you should just clear your cache tables.
It works
Thank you, Raemon!
Your advise was very helpful for me.
Now my code works fine.
The last (working) version is (for another people who maybe would have close problem).
I have mysql database, so I should use db_query instead of db_query_range.
And also I have some strange problems with query string creation.
So at the end I have created it in simplest way.
Congratulations, good to
Congratulations, good to hear.
translated for 6.x
I realize this is an old thread but I had a similar use case and needed my exposed node reference field in a view to function as an autocomplete field. I'm on drupal 6.x so I went ahead and translated the above solution. I figured I'd post back my translation since this was so helpful. Also, I did a bunch of digging but couldn't find any other solutions to this. If anyone knows of a better way to do this please feel free to pass on the info. I'm new to Drupal so any help would be appreciated...
Thanks.
subscribe.
subscribe.
Subscribe...
Subscribe...
subscribe
subscribe
subscribe
subscribe...
[at]Killua99 ~~
cck taxonomy select list
So I just had to do the same thing for a Content Taxonomy Field.
Thank you swolynski for posting. I had some 'An illegal choice' errors to work through, on my version, I prefill the field with All, and have it go away when user selects the box. Also if the user puts in an illegal choice, I give them a drupal message saying that they have put in a choice that is not valid, and again prefill the box with All.
Remove #options to avoid "An illegal choice"
I think I figured out an easier way to avoid the 'An illegal choice has been detected. Please contact the site administrator.' error message. Instead of generating the allowed options, remove #options using unset(). Without #options, the validation doesn't require that the user selected a valid option.
If they entered text that will not match a node id, I set the node id to 0 in the query. This makes it work properly, returning no results without throwing errors.
Here's my .module code for Drupal 6.x:
multiple autocomplete?
I have implemented an auto-complete text field for usernames using the Drupal forms API as below -
This field only works for selecting a single username. How can I implement a similar auto-complete field which allows selection of multiple users in a comma seperated list?
I have done this recently by
I have done this recently by using taxonomy code example. Mine was for Node Title Auto complete, but I think you'll be able to get it from here.
subscribing
This feature is badly required. My site have a reference node count of 6000+ (and growing) and having that all loaded in a dropdown list proves to be a suicide attempt.
Kevin & Siji
This has to be a part of
This has to be a part of http://drupal.org/project/views_autocomplete_filters
Cheers,
TechNikh
In 30 seconds set up Automated Visual testing of your website. Zero coding. https://drupal.org/project/drulenium
Ever dreamed of styling your view, We have a solution for you. https://drupal.org/project/views_stylizer
Solution using hook_form_alter and hook_form_validate
Hi there!
I found a simply solution using form hooks inspired by weekbeforenext comment:
I hope this would be useful and as TechNikh says, maybe this code has to be moved to Views Autocomplete Filters project.
Regards,
i'm hoping to implement this
i'm hoping to implement this for a Views 3.x exposed filter allowed values (or not?) select list (transformed to autocomplete textfield of course). I've been researching and there are lots of bits of code around for how to do this with Views 2.x as well as Views Autocomplete Filters module... but i cannot find anything related to how to do adjust the code like the above example in Views 3.x for a cck field. Could anyone help me out? Am i missing something?
I'd also be more than happy to pay someone $$ to help me get a working Views exposed filter cck autocomplete widget for views 3.x
-Cameron
Web Designer & Developer
Website Design and Development