-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
REGRESSION: dropdown changes requires the selectedItem to store entire option array item (label and value) to use template selecteditem #14172
Comments
Also related to #14171 |
Thanks a lot for reporting the issue! |
@cetincakiroglu so selectedOption prop is back, after it was removed right? 😁 |
still not fixed, tested with 16.9.0 @cetincakiroglu |
Could you please share an example? |
The issue I had on p-dropdown has been resolved on 16.9.0 https://stackblitz.com/edit/zkmdqg-gyeyzs?file=src%2Fapp%2Fdemo%2Fdropdown-template-demo.html,package.json Looks like a different issue. |
@pete-mcwilliams yeah that demo works, but i am getting errors in project, i have to isolate this reproduction case, will try to provide example |
The issue is resolved for me as well. I had check if <ng-template let-selectedItem pTemplate="selectedItem">
<div *ngIf="selectedItem" class="ml-2">
<i [class]="selectedItem.icon" class="mr-3"></i>{{selectedItem.label}}
</div>
</ng-template> |
if i do that then content inside template is not shown even tough value is there |
@jerkovicl @pete-mcwilliams Sorry to bother, but do any of you guys have I'm almost sure that filter of Need to investigate more. Will update. |
@eXpertise7 yes i have filter and autoDisplayFirst both and separately on some of dropdowns, |
ngModel should be the property specified in optionValue, that gives you link by reference to the option array rather than having to store the entire option as key to the options array (including the label). Can you provide a stackblitz repro showing your issue? |
@eXpertise7 another thing i noticed is if you use any pipe like async or translate inside pTemplate then label errors show up aswell like this:
|
I found I had to change to something like this from your example |
@pete-mcwilliams as soon as you do but if i remove null check then dropdown shows selected label but throws error translate pipe is a non pure pipe tough so it triggers on every change detection |
True, I can confirm it. I believe that happens because In the image above: Where "MY ->" is - that's my You can manipulate it's styles in component CSS file though In my example I had to do this to make stuff visually normally initially:
We should be asking @cetincakiroglu why |
@eXpertise7 good find, i am sure the cause is refactoring because on v16.6.0 everything worked normally |
Just a small update - about the issue above I stated with I needed to implicity put property I want to This is what will make people report issues or get them confused. I'm working with this awesome UI library for 6 years, and these breaking changes will frustrate people - stuff will not work on [email protected], if data bound to |
@eXpertise7 tried workaround with css but didnt help in my case |
related to #14241 |
Describe the bug
Previously the selected template would pass the entire option array item to the pTemplate="selectedItem", both the optionLabel and optionValue could be passed as parameters into p-dropdown, this allowed the optionValue to be stored in the ngModel.
The change has caused selectedItem template to receive only the value when optionValue is specified. The entire option item has to be stored as the selected value so that the label can be available in the template. This can be seen on the https://primeng.org/dropdown#template
It is undesirable to have to store the code and label as the selected item, imagine trying to change the label in the future in a json structure in a database for all rows.
16.8.0 demo use of dropdown with templates (breaking change requiring selectedItem to be entire option array item)
https://stackblitz.com/edit/zkmdqg?file=src%2Fapp%2Fdemo%2Fdropdown-template-demo.html
16.8.0 this should work allowing only the code to be persisted but does not as the template is only passed the optionValue.
https://stackblitz.com/edit/zkmdqg-buomly?file=src%2Fapp%2Fdemo%2Fdropdown-template-demo.html,package.json
16.4.2 working as it should same example as above with only primeng version change
https://stackblitz.com/edit/zkmdqg-ivcsef?file=src%2Fapp%2Fdemo%2Fdropdown-template-demo.html,package.json
Environment
see repros
Reproducer
https://stackblitz.com/edit/zkmdqg-buomly?file=src%2Fapp%2Fdemo%2Fdropdown-template-demo.html,package.json
Angular version
16.2.7
PrimeNG version
16.8.0
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
v18.17.0
Browser(s)
n/a
Steps to reproduce the behavior
use the repros
Expected behavior
we should be able to store a property of the option item and be able to use the pTemplate="selectedItem"
The text was updated successfully, but these errors were encountered: