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 | autoDisplayFirst not update value of dropdown #10768

Closed
marcioggs opened this issue Oct 25, 2021 · 2 comments
Closed

Dropdown | autoDisplayFirst not update value of dropdown #10768

marcioggs opened this issue Oct 25, 2021 · 2 comments
Assignees
Labels
LTS-FIXED-10.1.5 Fixed in PrimeNG LTS 10.1.5 LTS-FIXED-11.4.8 Fixed in PrimeNG LTS 11.4.8 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@marcioggs
Copy link

I'm submitting a ... (check one with "x")

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)

app.component.html:

<p-dropdown
  [options]="countries"
  [(ngModel)]="selectedCountry.code"
  optionValue="code"
  optionLabel="name"
  [showClear]="true"
>
  <ng-template pTemplate="selectedItem">
    <div class="country-item country-item-value" *ngIf="selectedCountry">
      <div>{{ selectedCountry.name }} {{ selectedCountry.code }}</div>
    </div>
  </ng-template>
  <ng-template let-country pTemplate="item">
    <div class="country-item">
      <div>{{ country.name }}</div>
    </div>
  </ng-template>
</p-dropdown>

app.component.ts

...
  countries: any[];
  selectedCountry = { name: null, code: null };

  constructor() {
    super();
    this.countries = [
      { name: 'Australia', code: 'AU' },
      { name: 'Brazil', code: 'BR' },
      { name: 'China', code: 'CN' },
      { name: 'Egypt', code: 'EG' },
      { name: 'France', code: 'FR' },
      { name: 'Germany', code: 'DE' },
      { name: 'India', code: 'IN' },
      { name: 'Japan', code: 'JP' },
      { name: 'Spain', code: 'ES' },
      { name: 'United States', code: 'US' },
    ];
  }
...

PS I couldn't create the StackBlitz because some errors occurs on the console and the application keeps stuck loading forever with the initial template:
https://stackblitz.com/github/primefaces/primeng-issue-template

Current behavior
The first option is not selected after clicking on it.
This only happens when there's no placeholder attribute present.
Options other than the first one can be selected without problems.

Expected behavior
First option should be selected after clicking on it.

Minimal reproduction of the problem with instructions
Open the page and click on the first option of the dropdown.

Please tell us about your environment:
Operating syste: Windows 10
IDE: IntelliJ
HTTP server: Angular live server

  • Angular version: 12.2.11

  • PrimeNG version: 12.2.1

  • Browser: *
    Microsoft Edge Version 90.0.818.41 (Official build) (64-bit)
    Google Chrome Version 72.0.3626.81 (Official Build) (64-bit)

  • Language: TypeScript 4.3.2

  • Node (for AoT issues): node --version = v14.15.4

@yigitfindikli yigitfindikli self-assigned this Oct 25, 2021
@yigitfindikli yigitfindikli added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Oct 25, 2021
@yigitfindikli yigitfindikli added this to the 12.2.2 milestone Oct 25, 2021
@yigitfindikli yigitfindikli removed their assignment Oct 27, 2021
@yigitfindikli yigitfindikli removed the Status: Pending Review Issue or pull request is being reviewed by Core Team label Oct 27, 2021
@yigitfindikli yigitfindikli removed this from the 12.2.2 milestone Oct 27, 2021
@yigitfindikli yigitfindikli added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Oct 27, 2021
@yigitfindikli yigitfindikli self-assigned this Oct 27, 2021
@yigitfindikli yigitfindikli added this to the 12.2.2 milestone Oct 27, 2021
@yigitfindikli yigitfindikli changed the title dropdown: Can't select first option when there's no placeholder Dropdown | autoDisplayFirst not update value of dropdown Oct 27, 2021
@yigitfindikli
Copy link
Contributor

Hi @marcioggs,

Thanks a lot for your report. The main problem is autoDisplayFirst doesn't update the value of the dropdown. And it's fixed in v12.2.2(Thanks to your investigation). But I think your approach does not want the autoDisplayFirst strategy. If you do not want the automatic first item selection then you can use [autoDisplayFirst]="false".

@marcioggs
Copy link
Author

Hello @yigitfindikli ,

thanks for the quick support and for letting me know about autoDisplayFirst!
Indeed this fixed for me on 12.2.1 :)

@yigitfindikli yigitfindikli added LTS-FIXED-11.4.8 Fixed in PrimeNG LTS 11.4.8 LTS-FIXED-10.1.5 Fixed in PrimeNG LTS 10.1.5 and removed LTS-PORTABLE labels Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTS-FIXED-10.1.5 Fixed in PrimeNG LTS 10.1.5 LTS-FIXED-11.4.8 Fixed in PrimeNG LTS 11.4.8 Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

2 participants