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

#62 BrokenAutocomplete.JPG20.05 KBANANSFPL
#54 1492260-54.patch6.02 KBrlmumford
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es). View
#50 entityreferencee_autocomplete_filter-1292260-50.patch5.57 KBWorldFallz
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entityreferencee_autocomplete_filter-1292260-50.patch. Unable to apply patch. See the log in the details link for more information. View
#48 1292260-entityreferencee_autocomplete_filter-48.patch4.59 KBWorldFallz
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1292260-entityreferencee_autocomplete_filter-48.patch. Unable to apply patch. See the log in the details link for more information. View
#33 Normal-operator.png3.26 KBhaydeniv
#33 Broken-Operator.png3.57 KBhaydeniv
#33 normal-null-behaviour.png3.46 KBhaydeniv
#33 normal-behaviour.png3.09 KBhaydeniv
#29 1492260-entityreference_views_autocomoplete_filter-29.patch5.97 KBhaydeniv
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es). View
#28 1492260-entityreference_views_autocomoplete_filter-28.patch5.83 KBhaydeniv
PASSED: [[SimpleTest]]: [MySQL] 119 pass(es). View
#27 step3.jpg57.28 KBycshen
#27 test.jpg5.48 KBycshen
#26 step1.jpg13.21 KBycshen
#26 step2.jpg5.27 KBycshen
#26 step3.jpg46.75 KBycshen
#26 effect.png3.41 KBycshen
#25 render-as-autocomplete.jpg34.32 KBsemiaddict
#25 broken-filter-error.jpg80.81 KBsemiaddict
#9 1492260-entityreference_views_autocomplete_filter-9.patch5.83 KBrlmumford
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es). View
#6 1492260-entityreference_views_autocomplete_filter-6.patch486 bytesrlmumford
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es). View
#7 1492260-entityreference_views_autocomplete_filter-7.patch5.83 KBrlmumford
PASSED: [[SimpleTest]]: [MySQL] 66 pass(es). View


Niremizov’s picture

+1, This would be nice.

John Pitcairn’s picture

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

Niremizov’s picture

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

John Pitcairn’s picture

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

samhassell’s picture

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

rlmumford’s picture

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

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

rlmumford’s picture

Status: Active » Needs review
5.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.

tim.plunkett’s picture

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.

rlmumford’s picture

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

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

tauno’s picture

Works as expected.

phoenix’s picture

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.

rlmumford’s picture

Status: Needs review » Reviewed & tested by the community
R.Muilwijk’s picture

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,
kclarkson’s picture

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.

ycshen’s picture

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.

Damien Tournoud’s picture

Category: bug » feature
photolimo’s picture

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?

plachance’s picture

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.

plachance’s picture

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

ycshen’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
pkil’s picture

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.

semiaddict’s picture

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 ?

ycshen’s picture

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.

MXT’s picture

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


semiaddict’s picture

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.

ycshen’s picture

3.41 KB
46.75 KB
5.27 KB
13.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.

ycshen’s picture

5.48 KB
57.28 KB

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

and this attach is good

haydeniv’s picture

Status: Patch (to be ported) » Needs review
5.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.

haydeniv’s picture

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

semiaddict’s picture

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

haydeniv’s picture

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?

jantoine’s picture

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']));
haydeniv’s picture

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

amberau79’s picture

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.

Kristen Pol’s picture

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.

rituraj.gupta’s picture

Status: Needs work » Needs review
rituraj.gupta’s picture

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

sinasalek’s picture

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

haydeniv’s picture

Status: Reviewed & tested by the community » Needs work

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

sinasalek’s picture

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

NancyDru’s picture

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?

yogeshchaugule8’s picture

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

sinasalek’s picture

Another 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

charlie charles’s picture

You can use the https://drupal.org/project/views_autocomplete_filters

As shown in this video tutorials


I found another way to do this too


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

nithinkolekar’s picture

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

joel_osc’s picture

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

class views_handler_filter_entityreference_autocomplete extends views_handler_filter_many_to_one {
  // Stores the exposed input for this filter.
  var $validated_exposed_input = NULL;

  function init(&$view, &$options) {
    parent::init($view, $options);
    // Find field info
    $field = field_info_field($this->definition['field_name']);
    $this->field = $this->definition['field_name'];
    $this->target_type = $field['settings']['target_type'];
mr.alinaki’s picture

joel_osc, your changes fixed this error for me! Thanks!

WorldFallz’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Needs work » Needs review
4.59 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1292260-entityreferencee_autocomplete_filter-48.patch. Unable to apply patch. See the log in the details link for more information. View

Here's an updated patch including the change from #46. Seems to be working fine so far.

Status: Needs review » Needs work

The last submitted patch, 48: 1292260-entityreferencee_autocomplete_filter-48.patch, failed testing.

WorldFallz’s picture

5.57 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entityreferencee_autocomplete_filter-1292260-50.patch. Unable to apply patch. See the log in the details link for more information. View

Not sure why that patch was not applyable for the bot. But forgot to add one of the files anyway. Updated patch attached.

WorldFallz’s picture

Status: Needs work » Needs review

lets poke the bot again...

Status: Needs review » Needs work

The last submitted patch, 50: entityreferencee_autocomplete_filter-1292260-50.patch, failed testing.

rlmumford’s picture

The most recent patch is still missing a file I think.


rlmumford’s picture

Status: Needs work » Needs review
6.02 KB
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es). View

Here's an updated patch.

ThomasJacobs’s picture

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

ikeigenwijs’s picture

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

idebr’s picture

Title: autocomplete option for views exposed filter » Add a Views autocomplete exposed filter as a field setting for selecting values

Updated the issue title to reflect this is a settings for the field, not for exposing an entityreference in Views.

idebr’s picture

Title: Add a Views autocomplete exposed filter as a field setting for selecting values » Add option to render entityreference Views exposed filter as an autocomplete field

Sorry, I misread the issue. It is actually about Views exposed filters, but the setting is on the base field.

colan’s picture

Status: Needs review » Needs work
+++ b/views/views_handler_filter_entityreference_autocomplete.inc
@@ -0,0 +1,114 @@
+    //$eids = $this->validate_entity_labels($form[$identifier], $form, $form_state, $values);

Functionality seems to work, but what's this line about? Can we remove it? Other than that, I'd say this is RTBC.

ShaxA’s picture

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

Shiraz Dindar’s picture

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

ANANSFPL’s picture

20.05 KB

Attaching photo to show the error.

iampuma’s picture

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

bucefal91’s picture


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.

bucefal91’s picture

Guys, 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