angular / angular/components

Support for setting option's control value to be a property of object and option's display value to be another property of the object

Open
#14,974 9 comments 3 reactions 0 assignees View on GitHub
area: material/autocomplete feature needs: discussion P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

I know that if we want the option's control value (what is saved in the form) to be different than the option's display value (what is displayed in the text field), we'll need to set the **displayWith** property on our autocomplete element. as explained here:

https://material.angular.io/components/autocomplete/overview#setting-separate-control-and-display-values

Suppose we have a user object like `{ id: 1, name: 'Abc' }`.

What if we want the option's control value (what is saved in the form) to be **user.id** and option's display value (what is displayed in the actual text field) to be **user.name**?

In my case I want to display a list of users in autocomplete options and when user selects a user, I want to display the selected user name on the user screen but when the form is submitted, I just want user.id to be posted to the server not user.name and not complete user object.

Contributor guide

Open the contributing guide

Research direction

Start with the linked Angular Material autocomplete documentation, especially the section on setting separate control and display values, and compare it with the user object example in the issue. Done means an autocomplete can display user.name after selection while submitting user.id rather than the name or entire object.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.