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

p-dropdown: Setting value from reactive form with dataKey attribute does not work properly #14178

Closed
nestorcamacho opened this issue Nov 22, 2023 · 1 comment
Labels
Resolution: Invalid Issue or pull request is not valid in the latest version

Comments

@nestorcamacho
Copy link

nestorcamacho commented Nov 22, 2023

Describe the bug

In version 16.7.2 the p-dropdown component does not work correctly when a patchValue is made only with the dataKey attribute. The dropdown seems to recognise the option to select but does not display any text. It works correctly if the complete object is defined in the patchValue.

Demo with PrimeNG 16.7.2

The option is selected but does not show the label.

Environment

Windows 10

Reproducer

https://stackblitz.com/edit/fdps8e-gd6q1x?file=src%2Fapp%2Fdemo%2Fdropdown-reactive-forms-demo.ts

Angular version

16.2.0

PrimeNG version

16.7.2

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.18.0

Browser(s)

No response

Steps to reproduce the behavior

  1. Creation of a dropdown in a reactive form with dataKey attribute .
<p-dropdown
      formControlName="city"
      [options]="cities"
      optionLabel="name"
      dataKey="code"
></p-dropdown>
  1. Defining the dropdown options objects.
this.cities = [
      { name: 'New York', code: 'NY' },
      { name: 'Rome', code: 'RM' },
      { name: 'London', code: 'LDN' },
      { name: 'Istanbul', code: 'IST' },
      { name: 'Paris', code: 'PRS' },
    ];
  1. Define the form
this.formGroup = new FormGroup({
      city: new FormControl<City | null>(null),
    });
  1. Making a patchValue of the form only with the dataKey property defined in the dropdown.
this.formGroup.patchValue({ city: { code: 'IST' } });

Expected behavior

Show the label when it is selected by dataKey as version 16.4.2.

Demo with PrimeNG 16.4.2

Demo with PrimeNG 16.4.2

@nestorcamacho nestorcamacho 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 22, 2023
@cetincakiroglu
Copy link
Contributor

@cetincakiroglu cetincakiroglu added Resolution: Invalid Issue or pull request is not valid in the latest version and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Invalid Issue or pull request is not valid in the latest version
Projects
None yet
Development

No branches or pull requests

2 participants