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

Dropdown: Preselected value not shown when using reactive forms #14241

Closed
Timmeeeey opened this issue Nov 29, 2023 · 19 comments · Fixed by #14331
Closed

Dropdown: Preselected value not shown when using reactive forms #14241

Timmeeeey opened this issue Nov 29, 2023 · 19 comments · Fixed by #14331
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@Timmeeeey
Copy link

Describe the bug

When using reactive forms with an initial value this value is not shown in the dropdown.
It shows only after clicking on the dropdown.

2023-11-29_10h02_26

Environment

Windows, Edge

Reproducer

https://stackblitz.com/edit/z2vojt

Angular version

17.0.0

PrimeNG version

17.0.0-beta.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.9.0

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@Timmeeeey Timmeeeey added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 29, 2023
@jerkovicl
Copy link

jerkovicl commented Nov 29, 2023

@Timmeeeey same issue here
even if your value is set during creating of form like this: new FormControl(value here), dropdown will not show selected value initially, it will only show it after dropdown click

@jerkovicl
Copy link

@Timmeeeey another thing, if you remove ? from selectedItem template value will be shown in dropdown but we will get error in console about item being null in selectedItem template
reproducer here:

@chaeller
Copy link

chaeller commented Nov 29, 2023

I have the same problem

PrimeNg 17.0.0-rc.1 = not OK
https://stackblitz.com/edit/uzpr21-z8gmpt

PrimeNg 17.0.0-beta.1 = not OK
https://stackblitz.com/edit/uzpr21-dhskbu

PrimeNg 16.9.1 with Angular 17 = not OK
https://stackblitz.com/edit/uzpr21-dpm6ab

PrimeNg 16.9.1 with Angular 16 = OK
https://stackblitz.com/edit/cnmrtn-bw3sgn

@jerkovicl
Copy link

@cetincakiroglu any updates on this? did you check reproducers?

@jerkovicl
Copy link

jerkovicl commented Dec 7, 2023

@cetincakiroglu tested with latest version v17.0.0, this is still not working, reproducer
check the error in console

@cetincakiroglu cetincakiroglu added this to the 17.1.0 milestone Dec 7, 2023
@cetincakiroglu
Copy link
Contributor

Thanks for the reproducer, we'll check and identify the issue.

@aturoczy
Copy link

I have the same issue. Last 2 days I tried to debug it, and finally found this thread :) The only "workaround" that I found to bind the value into the ngModel as well. But it is definitely a breaking change that the Angular 17 brought.

@mehmetcetin01140 mehmetcetin01140 self-assigned this Dec 12, 2023
cetincakiroglu added a commit that referenced this issue Dec 12, 2023
Fixed #14241 - Dropdown | Preselected value not shown when using reac…
@cetincakiroglu cetincakiroglu 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 Dec 13, 2023
@jerkovicl
Copy link

@cetincakiroglu this should be reopened, since issue is still there even with 17.1.0 fix
Reproducer

@aturoczy
Copy link

I'm going to try it soon with the new version. But yes, in the release notes this fix is there.

@cetincakiroglu
Copy link
Contributor

cetincakiroglu commented Dec 13, 2023

@cetincakiroglu this should be reopened, since issue is still there even with 17.1.0 fix Reproducer
Screenshot 2023-12-13 at 19 39 38

Are you sure? Your example is working actually, I didn't change anything just opened the example you've shared above.

@jerkovicl
Copy link

@cetincakiroglu this should be reopened, since issue is still there even with 17.1.0 fix Reproducer

Screenshot 2023-12-13 at 19 39 38

Are you sure? Your example is working actually, I didn't change anything just opened the example you've shared above.

Check the error in console

@cetincakiroglu
Copy link
Contributor

@cetincakiroglu this should be reopened, since issue is still there even with 17.1.0 fix Reproducer

Screenshot 2023-12-13 at 19 39 38
Are you sure? Your example is working actually, I didn't change anything just opened the example you've shared above.

Check the error in console

It's another issue, I'll create a new issue for it, thanks a lot for reporting

@jerkovicl
Copy link

@cetincakiroglu ok thats fine

@rburgst
Copy link

rburgst commented Dec 15, 2023

I still have occasional instances of the pre-selected item not showing up, however, its not trivial to reproduce.

@rburgst
Copy link

rburgst commented Dec 15, 2023

the problem seems to happen when initially the list of options if undefined. Will try and create a repro

@yassine-fy94
Copy link

The filterBy option is not working...

@xeexthemoth
Copy link

I've found a crazy work around... if you add virtual scroll to the component then it works!
e.g.
<p-dropdown
..
..
..
[virtualScroll]="true"
[virtualScrollItemSize]="10"

@xeexthemoth
Copy link

found a better hack!
last thing in your init

        setTimeout(() => {
            const originalValue = this.myForm.controls['myDropDownName'].value;
            this.myForm.controls['myDropDownName'].setValue('');
            this.myForm.controls['myDropDownName'].setValue(originalValue);
        });

seems to need to set value to an empty string first otherwise it doesn't work... so very strange... it is like the dropdown isn't updating its on screen paint once everything has completed... maybe a zone file bug in angular or a weird bug in primeng dropdown...

@GrantLiang
Copy link

image

https://stackblitz.com/edit/xdzkrc

In the above example, using Float Label
but No.3 case push item into options then the selected option will disappear

primeng : v17.14.1

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
Development

Successfully merging a pull request may close this issue.

10 participants