2

This is my case:

I have a content type advertisement with some fields and an entity reference of content type product. The widget type of the entity reference is autocomplete.

These are my settings of the autocomplete field:

enter image description here

enter image description here

When I create an advertisement I can type in the name of the product. But the product has also other fields like cnk. How can I make sure the autocomplete will search on the name AND the cnk?

2 Answers 2

6

You can use the functionality Views: Filter by an entity reference view that comes with the Entity Reference module to search on more fields.

To use this functionality you need to change Entity selection mode to Views: Filter by an entity reference view instead of Simple (with optional filter by bundle) on the settings for your entity reference field.

Entity reference - Entity selection mode - Filter by an entity reference view

First off you need to setup a View that lists your product nodes. Then add a display of the type Entity Reference.

Entity reference views display

You can exclude the field cnk from display but add it as a search field to the settings for the Format "Entity Reference List". If you don't exclude the field cnk from display it will show content from the field in the autocomplete widget.

enter image description here

No go back to the entity reference field and choose the view you just created under the settings for Views: Filter by an entity reference view.

1
  • Thanks !!! Works like charm. Exactly what I was looking for.
    – Sachin
    Commented May 24, 2017 at 12:50
2

Autocomplete will search against the referenced entity label (e.g. title). If you're set on using auto-complete then you may have to write your own custom module to provide alternative auto-complete behavior.

If you simply want to make it easier to search/select a referenced entity then I'd recommend giving the Entity Reference View Widget module a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.