1.0 Problem/Motivation
If there is an Existing Contact field with the widget type set to Autocomplete, it's usually possible to search for contacts on the form, using any of the data selected in the Contact Display Fields section. However, if Contact ID is added to the Contact Display Fields section, it's only possible to search with the Contact ID; entering any other data will return all contacts (the list is truncated so only a handful are actually displayed).
For example, if I include Display Name and Phone Number in the Contact Display Fields, I can search with either the Display Name or the Phone Number, and both work correctly. If I include Display Name and Contact ID, it breaks as described above; only the Contact ID can be used to search correctly.
2.0 Detailed steps to reproduce (embed screenshots)
I've attached the YAML from a webform which demonstrates the issue. Here are the steps used to create it:
- Create a new webform
- Enable CiviCRM processing and save
- Switch to the Build tab and edit the Existing Contact element
- Change the Form Widget to Autocomplete
- Hold Ctrl and click Contact ID in the Contact Display Field(s) section, so Contact ID and Display Name are both selected
- Save
- View the form
- Click the "x" to remove the current user from the Existing Contact field
- Try to search by Display Name
- Observe that the first handful of contacts in the database are all displayed in the list
- If the target contact is there, the string which was searched for will be in bold; usually the contact is not among the first handful in the database, so they cannot be selected
3.0 Proposed resolution
It's possible to work around the issue by never including Contact ID among the Contact Display Fields for an Autocomplete Existing Contact widget.
It would be much better if it could be included, with behaviour like Phone Number and other available fields. I haven't figured out what would need to change in the code to achieve this.
This was tested on Drupal 9.5.11 with webform 6.1.7 and webform_civicrm 6.2.4.