Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoComplete: Broken since PrimeNG 17.15.0 due to the new optionValue support #15393

Closed
ThoSap opened this issue Apr 29, 2024 · 8 comments · Fixed by #15792
Closed

AutoComplete: Broken since PrimeNG 17.15.0 due to the new optionValue support #15393

ThoSap opened this issue Apr 29, 2024 · 8 comments · Fixed by #15792
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@ThoSap
Copy link
Contributor

ThoSap commented Apr 29, 2024

Describe the bug

Since PrimeNG 17.15.0 the AutoComplete display is broken due to the new optionValue support.
In PrimeNG 17.14.0 wrapping an item in a SelectItem works and the selected item is displayed, but since PrimeNG 17.15.0 only [object Object] is displayed when an item is selected.

This bug was introduced with:
#14599
#15309

image

Environment

StackBlitz - PrimeNG AutocompleteReactiveFormsDemo broken selected item display

Reproducer

https://stackblitz.com/edit/yzm5ng?file=src%2Fapp%2Fdemo%2Fautocomplete-reactive-forms-demo.ts,src%2Fapp%2Fdemo%2Fautocomplete-reactive-forms-demo.html,package.json%3AL13-L13

Angular version

17.3.6 and 17.3.1 (from StackBlitz)

PrimeNG version

17.15.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

v20.11.1

Browser(s)

Microsoft Edge 124.0.2478.67

Steps to reproduce the behavior

Wrap the suggestion items in a PrimeNG SelectItem as it was done in
StackBlitz - PrimeNG AutocompleteReactiveFormsDemo broken selected item display

Expected behavior

It should work the same as it worked in PrimeNG 17.14.0:
See StackBlitz - PrimeNG AutocompleteReactiveFormsDemo working in PrimeNG 17.14.0
image

@ThoSap ThoSap added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Apr 29, 2024
@sandrotonon
Copy link
Contributor

sandrotonon commented Apr 30, 2024

You can add optionValue="label" to the autocomplete-config to show the label as value. See StackBlitz Demo.

@ThoSap
Copy link
Contributor Author

ThoSap commented Apr 30, 2024

I know, but in my case I need the whole SelectItem object or at least the SelectItem.value object, not only the label (the label is a computed field as you can see in my StackBlitz example).

It clearly worked before with PrimeNG 17.14.0.

@yorickp
Copy link

yorickp commented May 27, 2024

Feels related to #15495 (context there is [multiple]=true).

For those in search for a temporary potential workaround (as I agree on this being a bug), the same might work for this context (with [multiple]=false):

Add:

[optionValue]="optionValueFn"

to the p-autoComplete, with optionValueFn being initialised as:

optionValueFn = (option) => option as any

More details can be found here: #15495 (comment).

Curious whether this helps others in the meantime.

@ThoSap
Copy link
Contributor Author

ThoSap commented May 27, 2024

@yorickp your workaround works.
Maybe @sandrotonon will look into his PR again and fix this issue.

@joinsaturn
Copy link

joinsaturn commented Jun 2, 2024

Maybe can Help, do not use a mix o optionValue and optionLabel when you use an object.

This is something that wasn't clear to me when I read that the field was deprecated

If you use an object like actor={key: 1, name: 'super mario'} in version 17.15 I used Field as suggested.

Just an idea of example:
<p-autoComplete
dataKey="key"
field="name"
formControlName="actorControlName"

console.log(form.get('actorControlName')?.value);
{key: 1, name: 'super mario'}

Now field is deprecated and Primeng doc suggest to use optionLabel
/**
* Field of a suggested object to resolve and display.
* @group Props
* @deprecated use optionLabel property instead
*/

Just an idea of example:
<p-autoComplete
dataKey="key"
optionLabel="name"
formControlName="actorControlName"
.............

@pete-mcwilliams
Copy link
Contributor

It's a breaking change introduced in a minor patch, needs a fix.

@ThoSap
Copy link
Contributor Author

ThoSap commented Jun 4, 2024

@joinsaturn I didn't use optionValue or optionValueFn with optionLabel when updating to PrimeNG 17.15.0, I also never used the field input property, still, my AutoComplete completely stopped working as shown in this issue.

This has to be fixed.

@sandrotonon
Copy link
Contributor

sandrotonon commented Jun 4, 2024

@yorickp your workaround works. Maybe @sandrotonon will look into his PR again and fix this issue.

I'm currently working on a fix for this and #15495 and will create a new PR.

@mehmetcetin01140 mehmetcetin01140 added this to the 17.18.1 milestone Jun 6, 2024
@mehmetcetin01140 mehmetcetin01140 added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
6 participants