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.
Hello,
I think it would be nice to also have an autocomplete widget for views exposed filters.
Comment | File | Size | Author |
---|---|---|---|
#62 | BrokenAutocomplete.JPG | 20.05 KB | ANANSFPL |
#54 | 1492260-54.patch | 6.02 KB | rlmumford |
#50 | entityreferencee_autocomplete_filter-1292260-50.patch | 5.57 KB | WorldFallz |
#48 | 1292260-entityreferencee_autocomplete_filter-48.patch | 4.59 KB | WorldFallz |
#33 | Normal-operator.png | 3.26 KB | haydeniv |
Comments
Comment #1
Niremizov CreditAttribution: Niremizov commented+1, This would be nice.
Comment #2
John Pitcairn CreditAttribution: John Pitcairn commentedSimilar, but perhaps simpler to implement, I'd like a select list widget.
Comment #3
Niremizov CreditAttribution: Niremizov commented@John Pitcairn this is already done in module.... (select list)
Comment #4
John Pitcairn CreditAttribution: John Pitcairn commentedThanks, found the option. I was expecting to choose the widget type when adding the filter, not in the field configuration outside views.
Comment #5
samhassell CreditAttribution: samhassell commentedI would be interested in an autocomplete exposed filter for entityreference too.
Comment #6
rlmumfordEDIT: Sorry, forgot to add the new files to git before making the patch! Ignore this!
Comment #7
rlmumfordHere's a patch - followed the style of the select list patch (providing a behavior plugin). It might be better to make this the default, with the option to choose between auto-complete, select list and standard ID entry.
Comment #8
tim.plunkettPurely code style review, didn't test at all. Leaving at CNR.
Retain
Can $rc be a longer name?
This should be swapped, I think.
Comment #9
rlmumfordHere's a patch updated with the code style fixes above
Comment #10
tauno CreditAttribution: tauno commentedWorks as expected.
Comment #11
phoenix CreditAttribution: phoenix commentedI had some problems, but after analyzing the code and the info in comments above, I found the solution.
You need to go to the entityreference field on the content type you've created. Go to the field settings. On the bottom of the form there're 2 options to check:
- Enable Render Views filters as an autcomplete widget
- Enable Render Views filters as select list
The checkbox was my missing link. I hope it helps someone that tries this patch.
Conclusion: this patch works as expected.
Comment #12
rlmumfordComment #13
R.Muilwijk CreditAttribution: R.Muilwijk commentedI ran this patch on the current dev but I can't seem to find how this can be working without this patch:
Comment #14
kclarkson CreditAttribution: kclarkson commentedThanks for the patch. One thing that I have noticed is that in only works on Views Pages.
The filter does not work when you use a views content pane or block. The results just show an empty page.
Many times I use panels to create a custom page at which I then add a view content pane. The taxonomy filters seem to work great but the Group Audience does not.
Comment #15
ycshen CreditAttribution: ycshen commentedi create a view reference with nid,name. i choose name for autocomplete search.
then i create a content type and add a field use this view reference .
it cant search name,just search nid.
Comment #16
Damien Tournoud CreditAttribution: Damien Tournoud commentedComment #17
photolimo CreditAttribution: photolimo commentedI agree with John Pitcairn here,
I was expecting the option to add autocomplete to a filter in Views, not in the content type "manage fields".
Where should we add some documentation to this to prevent further confusion?
Comment #18
plachance CreditAttribution: plachance commentedI've backported patches #9 and #13 to 7.x-1.0-rc5 but it didn't worked. There's no need for patch #13 if you change this line
$autocomplete_path .= $this->definition['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/';
into this line
$autocomplete_path .= $this->definition['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/NULL';
in views_handler_filter_entityreference_autocomplete.inc.
It will now load the correct url as in entityreference.module lines ~775-815.
There's also the view field option "expose-multiple" (Allow multiple selections) that is ignored because the url "entityreference/autocomplete/tags" is always loaded. It should load the url "entityreference/autocomplete/single" if the option allow multiple selections is false like in entityreference.module lines ~775-815.
Comment #19
plachance CreditAttribution: plachance commentedThere's a bug with patch #9 when a user enter a value in an entityreference_autocomplete filter in a view if he doesn't select a suggestion.
Notice : Undefined index: #field_name in _entityreference_autocomplete_tags_validate() (line 856 in sites/all/modules/entityreference/entityreference.module).
Line 856 :
$field = field_info_field($element['#field_name']);
Related : In a node creation form, if the value exists, it will associate it even if the nid isn't between () in the textbox. But in a view filter, no result will be returned. The nid must be present between ().
Comment #20
ycshen CreditAttribution: ycshen commentedhttp://drupal.org/files/entityreference-views-autocomplete-1791914.patch
this patch fix the bug i posted in #15
Comment #21
pkil CreditAttribution: pkil commentedI'm getting an AJAX error when I start to type in the exposed filter.
Error Code: 403
Access Denied.
Has anyone received this error, or know how to fix it?
edit: #18 resolved this issue.
Comment #22
semiaddict CreditAttribution: semiaddict commentedI'm trying the patch of #9 on the latest stable release (7.x-1.0), but when adding an entityreference filter I keep getting the error "Broken/missing handler".
Here are the modifications I've done as per the patch:
- created the file entityreference/views/views_handler_filter_entityreference_autocomplete.inc
- created the file entityreference/plugins/behavior/views-autocomplete.inc
- created the file entityreference/plugins/behavior/EntityReferenceBehavior_ViewsAutocomplete.class.php
- added the line "files[] = views/views_handler_filter_entityreference_autocomplete.inc" to the module's info file
- flushed all caches
I'm guessing views is not finding the views_handler_filter_entityreference_autocomplete class.
Am I missing something ?
Comment #23
ycshen CreditAttribution: ycshen commentedreply to #22
maybe you can provide more information.when you create a entityreference display in your view,and what you have done before the error "Broken/missing handler" appeared.
Comment #24
MXTI'm not sure to understand exactly this feature request, but... can this be related to:
In order use Views Exposed Filters, add an option to open Entityreference Views in a modal dialog window
?
Comment #25
semiaddict CreditAttribution: semiaddict commentedmaybe you can provide more information.when you create a entityreference display in your view,and what you have done before the error "Broken/missing handler" appeared.
Thank you ycshen for your reply.
I get the error (see "broken-filter-error.jpg" attached) when trying to add the entityreference filter to any view (even a completely new view).
Here are the steps I followed to get the error:
Any help is highly appreciated.
Comment #26
ycshen CreditAttribution: ycshen commentedreply#25
hi semiaddict,
i guess you create a wrong view display.from the attach image broken-filter-error.jpg you create a page display and you should create a entity reference display in your view.
step.1 create a view and add a entity reference display
step.2 in this display FORMAT click settings,and choose which field you what search in your atuocomplete.
step.3 create a field with entity reference type,and in its setting "ENTITY SELECTION" Mode choose "Views: Filter by an entity reference view" and View used to select the entities choose the view display your created."ADDITIONAL BEHAVIORS" choose Render Views filters as an autcomplete widget.
i hope that my reply will help you,and you can test the patch in #9 and #13.
there are some simple Screenshots in the attach.
Comment #27
ycshen CreditAttribution: ycshen commentedsorry,i upload wrong Screenshots step3.jpg effect.png in #26 .
and this attach is good
Comment #28
haydeniv CreditAttribution: haydeniv commentedNo big changes here. Just applied the fix in #18 which seems to be in line with how other ER autocomplete widgets are working. I tested it in my environment so if the testbot is happy, I'm saying this one is RTBC.
The problem with the error #15 if the user does not actually select a value is bigger than this issue and I think it is more important to get this functionality out then let that bug hold us up.
#22 by semiaddict is a problem with how (s)he ordered creating the view not a bug with this patch.
Comment #29
haydeniv CreditAttribution: haydeniv commentedMissed:
This patch applies that behavior as well.
Comment #30
semiaddict CreditAttribution: semiaddict commentedIndeed, the problem I encountered in #22 was due to a misunderstanding of how the patch worked.
Thank you.
Comment #31
haydeniv CreditAttribution: haydeniv commentedI was going to mark this as RTBC but as I did add a small change anybody else on here want to give this patch a test and RTBC this?
Comment #32
jantoine CreditAttribution: jantoine commentedThis is not RTBC.
Scenario: I have two content types, company and product. I added an Entity Reference field (field_company) to the product content type for selecting which company owns any given product. I also track users of companies, so I added that same field (field_company) to the user entity. I created a user report (User View) where I added a filter on the company field (field_company). The code below is loading the instance of the field that belongs to the solution content type, so the autocomplete returns no results.
views_handler_filter_entityreference_autocomplete.inc line 31
Comment #33
haydeniv CreditAttribution: haydeniv commentedAnother problem I discovered:
What should happen:
Screenshots:
Normal Field Behavior without NULL operators:
Normal Field Behavior with NULL operators:
Entity reference filter without NULL operators:
Entity reference filter with NULL operators:
Comment #34
amberau79 CreditAttribution: amberau79 commentedThank you so much for the great functionality in the patch, however heads up:
If running on Apache on a vhost with Multiviews enabled this does not work (path returns an ajax 404, despite also returning correct response text). Removing Multiviews from the vhost configuration fixes.
Comment #35
Kristen PolI applied the patch from #29 and updated the field to use the new option. The autocomplete field comes on the view for the exposed filter but the blue loading circle is spinning constantly and the autocomplete isn't working. If I fill in the entire text, then the option shows up. But clicking the Apply button doesn't work.
[UPDATE] Checked the error log and found:
[UPDATE2] If I brute force set the match_operator like:
Then it works (though the blue circle still spins all the time).
So... it appears the match_operator needs to be set to CONTAINS but that isn't an option when I configure the exposed filter... it just has "is one of", etc.
Comment #36
rituraj.gupta CreditAttribution: rituraj.gupta commented#28: 1492260-entityreference_views_autocomoplete_filter-28.patch queued for re-testing.
Comment #37
rituraj.gupta CreditAttribution: rituraj.gupta commentedHello,
I applied patch from #9. but still its not working. I have updated entity reference module and inc file and other file as per suggested by all above users. but not working.
I am worried. How could it get solved ?
Regard's
Ritu raj
Comment #38
sinasalek CreditAttribution: sinasalek commented@rituraj.gupta it was confusing for me too :) i was expecting the new setting options to be in views filter settings but it's not! which is strange because it makes it much less flexible. for example you can't have filter by id in one views and autocomplete filter on another view for the same field.
You must edit your field in content type and at the end of the page there is a new option "Render Views filters as an autcomplete widget"
Note that the patch 29 applied against dev cleanly and the module works well. Tx
I'm going to mark it as RTBC
Comment #39
haydeniv CreditAttribution: haydeniv commentedI don't believe #33 and #35 have been resolved.
Comment #40
sinasalek CreditAttribution: sinasalek commentedIncompatibility with field permissions module,
Auto-complete does not show when user does not have field create privilege
Comment #41
NancyDruThis issue has been open for two years and there is a security update against the module since then. Can we get something committed and go from there?
Comment #42
yogeshchaugule8 CreditAttribution: yogeshchaugule8 commented#29 patch works perfect, with comment by phoenix on #11
Comment #43
sinasalek CreditAttribution: sinasalek commentedAnother issue i encountered is that this patch uses field widget settings to display the views exposed filter. It causes several different issues
- Incompatibility with field permission module (Auto-complete does not show when user does not have field create privilege)
- The same widget should used for field should be used for views filter. for example if you want to use select list on form and auto complete for views filter it won't work and does show any matches when the text is entered
I think that it should have its own settings in views filter instead of relying entirely on field settings
Comment #44
charlie charles CreditAttribution: charlie charles commentedYou can use the https://drupal.org/project/views_autocomplete_filters
As shown in this video tutorials
https://www.youtube.com/watch?v=CkyIYnYswko
I found another way to do this too
Goto
Views > Advanced > Relationships
Add a "Entity Reference" from a field in your content type
Then this will give you option of autocomplete exposed filters in Views
I hope that's helpful
Comment #45
nithinkolekar CreditAttribution: nithinkolekar commentedI am bit confused about this patch whether , it is for "autocomplete option for any views exposed filter" or just "autocomplete option for views exposed filter where display is of type entityreference"
I am trying to test this patch against default admin/content view by adding ER field to article content type and adding that field to views after configuring relationship.
After applying #29 patch autocomplete widget is showing.When entity(simple node) input is given into autocomplete field it is not filtering content , instead showing empty view with "No content available."
In ER field's configuration both autocomplete and selection list option is provided which is of type checkbox, I think it should be radio button instead right? b/c any one widget will be rendered in views. When both checkbox are enabled selection list is rendered.
Comment #46
joel_osc CreditAttribution: joel_osc commentedI am wondering if anyone else has noticed errors like:
Notice: Array to string conversion in views_many_to_one_helper->ensure_my_table() (line 896 of /var/www/mysite/sites/all/modules/contrib/views/includes/handlers.inc).
For me it is occurring on the view with a default value set in the autocomplete. I did some debugging it seems above line in handlers.inc references $this->handler->field as a string, whereas this autocomplete handler sets it to the field_info array. The following modification fixes the error, and autocomplete 'seems' to work still. I was wondering if anyone else had some thoughts.
Comment #47
mr.alinaki CreditAttribution: mr.alinaki commentedjoel_osc, your changes fixed this error for me! Thanks!
Comment #48
WorldFallz CreditAttribution: WorldFallz commentedHere's an updated patch including the change from #46. Seems to be working fine so far.
Comment #50
WorldFallz CreditAttribution: WorldFallz commentedNot sure why that patch was not applyable for the bot. But forgot to add one of the files anyway. Updated patch attached.
Comment #51
WorldFallz CreditAttribution: WorldFallz commentedlets poke the bot again...
Comment #53
rlmumfordThe most recent patch is still missing a file I think.
views-autocomplete.inc
Comment #54
rlmumfordHere's an updated patch.
Comment #55
Chewi3 CreditAttribution: Chewi3 commentedI have tested the updated patch from #54 and I can say that it seems to be working fine (at least for me).
Thanks for the patch!
Comment #56
ikeigenwijs CreditAttribution: ikeigenwijs commented#11
We dont have the
- Enable Render Views filters as an autcomplete widget
option in Additional behaviors at bottum of contenttype field settings (the as select list is available)
The autocomplete works for user fields as entity reference fields
The autocomplete does not work for node entity fields as entity reference fields with or without relationship
Comment #57
idebr CreditAttribution: idebr commentedUpdated the issue title to reflect this is a settings for the field, not for exposing an entityreference in Views.
Comment #58
idebr CreditAttribution: idebr commentedSorry, I misread the issue. It is actually about Views exposed filters, but the setting is on the base field.
Comment #59
colanFunctionality seems to work, but what's this line about? Can we remove it? Other than that, I'd say this is RTBC.
Comment #60
ShaxA CreditAttribution: ShaxA commentedThe patch has one issue. It is working fine with views page display for example. But if you want a content pane display. Then you will not get the correct filter. The value becomes "Array" and it is not filtering anything.
Comment #61
Shiraz DindarI cannot get the patch (#56, applied to latest dev of entityreference) to work at all, in that when I check "Render Views filters as an autocomplete widget" I get "The selected behavior handler is broken." (immediately via ajax in the field config page). The view filter config is unchanged and the exposed filter in the view is unchanged.
Comment #62
ANANSFPL CreditAttribution: ANANSFPL commentedAttaching photo to show the error.
Comment #63
iampumaTried patching with #54. Clearing the caches will solve the 'selected behavior handler broken' issue. And afterwards adding an exposed filter with autocompletion works.
However the 'Remember the last selection' is not and is giving an error. The exposed filter value is as well than set to 'array'.
Comment #64
bucefal91 CreditAttribution: bucefal91 commentedHello!
I am not sure whether it applies to the majority of people here, but something similar can be achieved through Synonyms views filters: #2667834: Synonyms-friendly widgets for Entity reference field exposed filters in Views
I've just uploaded a patch there that offers an autocomplete views filter for entityreference fields and it seems to do the job (at least as far as I could test it). In the simplest configuration (when you do not enable any synonyms) that filter will work precisely as entity autocomplete. I am planning to tag a new stable release of Synonyms within next few weeks, so this functionality is a month or so short from being in the stable release of Synonyms.
Comment #65
bucefal91 CreditAttribution: bucefal91 commentedGuys, as promised in my previous comment. The synonyms-friendly autocomplete/select views filter for entity reference field has just been released within Synonyms module: https://www.drupal.org/node/2720481
Comment #66
heyddi CreditAttribution: heyddi commentedGreat patch! Thanks for the work, I am currently having timeout issues on some filter with very large select list.
I patched entity reference but I am experiencing an issue with the filter. My field is in multiple content types. And in the code, I found this:
So is takes the first instance but in my case, each bundle doesn't necessarily store all the datas. For example, in my estimates, I can have a client that I don't have in my invoices. So if invoices are the first instance read by "field_read_instances", it will not return the results that I need.
Also, wouldn't interesting to be able to filter on any content created, even if hasn't been used in the field (it would basically return an empty views result, but at least users will know there are no results)?
I will try to see if I can make up something on my side for this.
Comment #67
sinasalek CreditAttribution: sinasalek at Practicalidea commented