Using a View to display the elements in the Autocomplete widget

Last updated on
24 December 2018

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Overview

This short guide is a how-to on using a View to display the elements in the Autocomplete widget of the Entity Reference module.

Example Use Case

A user wants to show in the Autocomplete widget of an Entityreference field the node ID next to the titles in the dropdown list. The reason behind the idea is to differentiate between multiple nodes with same title.

Example:

  • This is a title - (3)
  • This is a title - (2)
  • This is a title - (1)

Creating the View

Install the Views and Entity Reference modules, create a new View and Add a Entity Reference Display

Adding a Views Display

Then Add in the fields the content title and the nid, click in the nid and check Exclude from display, Save and click in the title and go to rewrite the output of the title as [title] - ([nid])

Adding fields
Adding fields

Go to edit the settings of the format and check the title, this will allow you to search by title.

Configuring the search

Save the view.

Configuring the field

Go to edit your Entity Reference field and select in the Mode Views: .... (like the following image) and select your View (in this case the name is: articles_with_id) and save the settings:

Configuring the field

Using the Autocomplete Widget

Then go to see the result

Configuring the field

References

http://drupal.stackexchange.com/q/187869/28275

Help improve this page

Page status: No known problems

You can: