primefaces / primeng

The Most Complete Angular UI Component Library
https://primeng.org
Other
10.49k stars 4.6k forks source link

Autocomplete: "[object Object]" displayed when optionLabel input is used and the computed label value is null or undefined #16040

Open fredpeaks opened 3 months ago

fredpeaks commented 3 months ago

Describe the bug

The problem is at this line of code : https://github.com/primefaces/primeng/blob/e142de683b9cbcf2342774e9390ee09b0934580f/src/app/components/autocomplete/autocomplete.ts#L787C17-L787C59

It should not return the full object when the computed label is null or undefined.

Environment

not relevant

Reproducer

No response

Angular version

18

PrimeNG version

17.18.4

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

latest

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

maruthumj commented 3 months ago

@fredpeaks can you please create a reproducer in stackblitz?

MW8086 commented 3 months ago

Hello, I have a similar problem. To reproduce, replace
this.formGroup = new FormGroup({ selectedCountry: new FormControl<object | null>(null) });

with

this.formGroup = new FormGroup({ selectedCountry: new FormControl<object | null>({ "name": null, "code": null }) });

in the src\app\showcase\doc\autocomplete\reactiveformsdoc.ts file