Using a View to display the elements in the Autocomplete widget
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

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])


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

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:

Using the Autocomplete Widget
Then go to see the result

References
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion