I think it would be nice to also have an autocomplete widget for views exposed filters.


+1, This would be nice.

Similar, but perhaps simpler to implement, I'd like a select list widget.

@John Pitcairn this is already done in module.... (select list)

Thanks, found the option. I was expecting to choose the widget type when adding the filter, not in the field configuration outside views.

I would be interested in an autocomplete exposed filter for entityreference too.

new486 bytes
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]

EDIT: Sorry, forgot to add the new files to git before making the patch! Ignore this!

Status:Active» Needs review
new5.83 KB
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]

Here'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.

Purely code style review, didn't test at all. Leaving at CNR.

+++ b/views/views_handler_filter_entityreference_autocomplete.incundefined
@@ -0,0 +1,109 @@
+      // Retain the helper option


+++ b/views/views_handler_filter_entityreference_autocomplete.incundefined
@@ -0,0 +1,109 @@
+    $rc = parent::accept_exposed_input($input);
+    if ($rc) {

Can $rc be a longer name?

+++ b/views/views_handler_filter_entityreference_autocomplete.incundefined
@@ -0,0 +1,109 @@
+    $identifier = $this->options['expose']['identifier'];
+    if (empty($this->options['expose']['identifier'])) {
+      return;

This should be swapped, I think.

new5.83 KB
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es).
[ View ]

Here's a patch updated with the code style fixes above

Works as expected.

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

Status:Needs review» Reviewed & tested by the community

I ran this patch on the current dev but I can't seem to find how this can be working without this patch:

diff --git a/sites/all/modules/contrib/entityreference/entityreference.module b/sites/all/modules/contrib/entityreference/entityreference.module
index 425c8aa..f199daf 100644
--- a/sites/all/modules/contrib/entityreference/entityreference.module
+++ b/sites/all/modules/contrib/entityreference/entityreference.module
@@ -100,10 +100,10 @@ function entityreference_menu() {
     'access callback' => TRUE,
     'type' => MENU_CALLBACK,
-  $items['entityreference/autocomplete/tags/%/%/%'] = array(
+  $items['entityreference/autocomplete/tags/%/%/%/%'] = array(
     'title' => 'Entity Reference Autocomplete',
     'page callback' => 'entityreference_autocomplete_callback',
-    'page arguments' => array(2, 3, 4, 5),
+    'page arguments' => array(2, 3, 4, 5, 'NULL', 6),
     'access callback' => TRUE,
     'type' => MENU_CALLBACK,

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

Category:feature» bug

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

Category:bug» feature

I 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?

I'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.

There'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 ().

Status:Reviewed & tested by the community» Patch (to be ported)

I'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.

I'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 ?

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

I'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


new80.81 KB
new34.32 KB

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.

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:

  • applied the patch on the latest release version (7.x-1.0)
  • checked the "Render Views filters as an autcomplete widget" checkbox in the field settings (see "render-as-autocomplete.jpg" attached)
  • created a new content view
  • added the entityreference field as a filter

Any help is highly appreciated.

new3.41 KB
new46.75 KB
new5.27 KB
new13.21 KB


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.

new5.48 KB
new57.28 KB

sorry,i upload wrong Screenshots step3.jpg effect.png in #26 .

and this attach is good

Status:Patch (to be ported)» Needs review
new5.83 KB
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]

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

new5.97 KB
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es).
[ View ]


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.

This patch applies that behavior as well.

Indeed, the problem I encountered in #22 was due to a misunderstanding of how the patch worked.
Thank you.

I 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?

Status:Needs review» Needs work

This 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

// Sniff out the entity and bundle this appears on - there's probably a
// nicer way of doing this but for now we'll take the first instance we
// find of the field and use that. This should be ok, because allowed
// bundles are usually set as field settings.
$instances = field_read_instances(array('field_name' => $this->definition['field_name']));

new3.09 KB
new3.46 KB
new3.57 KB
new3.26 KB

Another problem I discovered:

  1. Create an exposed filter
  2. Expose operator
  3. Save View
  4. Try to set operator to Is Empty NULL or Is Not Empty (Not NULL)
  5. Nothing happens NULL and Not NULL values are still returned.

What should happen:

  1. The autocomplete text field should disappear when NULL or Not NULL is selected
  2. The view should actually filter out NULL and Not NULL results.

Normal Field Behavior without NULL operators:
Normal without NULL
Normal Field Behavior with NULL operators:
Normal with NULL

Entity reference filter without NULL operators:
Broken without NULL
Entity reference filter with NULL operators:
Broken with NULL

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

I 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:

Notice: Undefined index: match_operator in entityreference_autocomplete_callback_get_matches() (line 1033 of /docroot/sites/all/modules/contrib/entityreference/entityreference.module).

[UPDATE2] If I brute force set the match_operator like:

    if (! isset($instance['widget']['settings']['match_operator'])) {
      $instance['widget']['settings']['match_operator'] = 'CONTAINS';

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.

Status:Needs work» Needs review

Version:7.x-1.x-dev» 7.x-1.0
Priority:Normal» Major


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 ?

Ritu raj

Issue summary:View changes
Status:Needs review» Reviewed & tested by the community

@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

Status:Reviewed & tested by the community» Needs work

I don't believe #33 and #35 have been resolved.

Incompatibility with field permissions module,
Auto-complete does not show when user does not have field create privilege

This 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?

#29 patch works perfect, with comment by phoenix on #11