Hi,
I'm trying to add an autocomplete form field via form API.
Usually Entity Reference Autocomplete works quite well.
But it does not work for CRM core contacts because it is trying to filter by label. Since contacts don't declare a label it does not work.
Usually the label is a column on the entity, but since we usually filter by contact name this is not possible since the name is a field stored in a different table.
So my first idea was to create a label field that is always updated on entity save to copy the name information to that field.
Then the entity could be filtered by label ( name ).

What do you think about this? Any other ideas for a better approach? Maybe there is even a possibility to have an autocomplete reference field via form api that i didn't see.

Comments

bechtold created an issue. See original summary.

bechtold’s picture

This module uses the same approach to filter by label: Entity Autocomplete

bechtold’s picture

Title: Integration with entityreference_autocomplete » Form API autocomplete
Issue summary: View changes

I change the title because an integration with this specific module is not needed, if there is a different solution to my initial problem.

bechtold’s picture

Awesome, I just checked out the dev branch and it seems that you already implemented this.
My first test with Entity Reference Autocomplete seems to work, i continue testing.

RoSk0’s picture

Hi,
Yes, we switched to this approach to have more flawless integration with entityreference and other modules.

RoSk0’s picture

Version: 7.x-0.980 » 7.x-1.x-dev
Component: Code » CRM Core Contact

Can you please confirm that new approach is working for you?

RoSk0’s picture

mikez93’s picture

I just upgraded from 7.x-0.980 to 7.x-1.0 and lost most (but not all) autocomplete functionality. Sounds like I need to install the Entity Reference Autocomplete module? True?

https://www.drupal.org/project/entityreference_autocomplete

mikez93’s picture

Learning more here. It's not the autocomplete functionality that I lost but it seems the install process failed to populate the new "Name" column that is added to the crm_core_contact table at install. I've created a new issue for this:
https://www.drupal.org/node/2886899

grahl’s picture

Status: Active » Closed (outdated)

Closing outdated issue, please reopen if still relevant.