primeng icon indicating copy to clipboard operation
primeng copied to clipboard

autocomple multiple : can't display labels

Open stephane-tessier opened this issue 11 months ago • 13 comments

Describe the bug

When using autocomplete with multiple = true and objects like [{label: 'toto', value: {}}], the selected items cannot display their labels properly :

<li
                    #token
                    *ngFor="let option of modelValue(); let i = index"
                    [ngClass]="{ 'p-autocomplete-chip-item': true, 'p-focus': focusedMultipleOptionIndex() === i }"
                    [attr.id]="id + '_multiple_option_' + i"
                    role="option"
                    [attr.aria-label]="getOptionLabel(option)"
                    [attr.aria-setsize]="modelValue().length"
                    [attr.aria-posinset]="i + 1"
                    [attr.aria-selected]="true"
                >

let option of modelValue() is wrong : it's not an option (label+value) but only a value. This should be renamed as value, and a function similar to inputValue() should be used to fetch the selected options among the options list

BR

Pull Request Link

No response

Reason for not contributing a PR

  • [X] Lack of time
  • [X] Unsure how to implement the fix/feature
  • [X] Difficulty understanding the codebase
  • [ ] Other

Other Reason

No response

Reproducer

x

Environment

prime 18.0.2

Angular version

18.0.2

PrimeNG version

v18 (LTS Only)

Node version

No response

Browser(s)

No response

Steps to reproduce the behavior

use an autocomplete with complexe objects

Expected behavior

labels should display properly

stephane-tessier avatar Jan 08 '25 13:01 stephane-tessier

Can you provide a stackblitz reproducer? I think have this scenario in my application and it works fine. You have to set the [optionLabel] property of the p-autocomplete.

davidda avatar Jan 16 '25 08:01 davidda

Due to PrimeTek's demanding roadmap for PrimeNG, this issue is available for anyone to work on. Make sure to reference this issue in your pull request. :sparkles: Thank you for your contribution! :sparkles:

github-actions[bot] avatar Jan 16 '25 09:01 github-actions[bot]

More information is needed to find a solution. A runnable StackBlitz example and additional details would be helpful.

github-actions[bot] avatar Jan 16 '25 09:01 github-actions[bot]

@davidda but not only that , also optionValue="value" needs to be set since the default is different

petogriac avatar Jan 24 '25 14:01 petogriac

https://stackblitz.com/edit/stackblitz-starters-uppvnx3z?file=src%2Fapp%2Fapp.component.ts

stephane-tessier avatar Feb 07 '25 08:02 stephane-tessier

Bump

BeGj avatar Mar 03 '25 09:03 BeGj

We have the same issue on our apps and this makes it impossible to finalize the upgrade to primeng19. I confirm that the stackblitz linked by @stephane-tessier reproduces the exact issue we have.

WillBoig avatar Mar 17 '25 10:03 WillBoig

The issue is still present in primeng 19.0.10. I have updated the stackblitz of @stephane-tessier to show that it does not work with multiple attribute or without it :

https://stackblitz.com/edit/stackblitz-starters-gdwelehl?file=src%2Fapp%2Fapp.component.html

WillBoig avatar Mar 18 '25 16:03 WillBoig

Is there anyone from the dev teams that looks at issues on this repo ??

WillBoig avatar Mar 21 '25 09:03 WillBoig

A work around I found to work is to map the select item to itself i.e.

{ label: '', value: '', item: { label: '', value: '' }}

Then set optionValue="item"

ryann3588 avatar Mar 27 '25 15:03 ryann3588

Same problem reproduced with primeng demo: https://7xfmvtbs.stackblitz.io

gmaggio-ca avatar Apr 04 '25 08:04 gmaggio-ca

Yesterday, created a pull request that fix the issue.

Please review asap: https://github.com/primefaces/primeng/pull/18044

Image

Image

gmaggiodev avatar Apr 08 '25 08:04 gmaggiodev

I just had to change the 'value' field to anything else, it took me two hours to figure out...

Example Stackblitz (forked from @stephane-tessier).

filiptrivan avatar May 30 '25 16:05 filiptrivan

6 months without a fix ?! There is a PR but nobody merge it.

Please fix this quickly.

In the meantime, we're using ryann3588's work around

rlittolff-rofim avatar Jun 30 '25 12:06 rlittolff-rofim

Fixed for next version.

@gmaggiodev could you please check the fix? Thanks a lot!

mertsincan avatar Sep 23 '25 14:09 mertsincan

Fixed for next version.

@gmaggiodev could you please check the fix? Thanks a lot!

@mertsincan I've just tested it using the showcase extension with problem use case that I wrote in my PR (https://github.com/primefaces/primeng/pull/18044) but it works partially. I still have a problem when passing initially the selection array (as array of codes). It doesn't resolve its labels:

Image

I can do a PR with new showcase docs to make easier for you reproducing the cases (or you can pick it from my PR).

Let me know

gmaggio-ca avatar Sep 23 '25 16:09 gmaggio-ca