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: "0" Value in optionValue, causes Label to be replaced by Placeholder #14715

Closed
eduardheller89 opened this issue Feb 5, 2024 · 6 comments · Fixed by #14719
Closed
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@eduardheller89
Copy link
Contributor

Describe the bug

When the value of the dropdown is 0, the placeholder value is still shown in the input.

This is the line causing the issue

return this.modelValue() ? this.getOptionLabel(this.selectedOption) : this.placeholder || 'p-emptylabel';

this Line in component.ts causes '0' to be accepted as False. You should check for null or undefined.

Thanks

Environment

Win10/chrome

Reproducer

No response

Angular version

17.1.2

PrimeNG version

17.5.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.19.0

Browser(s)

Chrome 121

Steps to reproduce the behavior

  1. Set Dropdown to a value in optionValue to 0.
  2. Set Dropdown placeholder
  3. Change the value of the dropdown in the ui to the corresponding value with Value 0
  4. Placeholder still remains in the input

Expected behavior

The optionLabel should show the Label of the optionValue with Value 0

@eduardheller89 eduardheller89 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 5, 2024
@Cr3aHal0
Copy link
Contributor

Cr3aHal0 commented Feb 5, 2024

Hi,

Not sure if this is by design or if more options should be available other than '0' such as true, false or empty string. If empty/null comparison is enough, the linked PR should be okay

@rosenthalj
Copy link
Contributor

This issue is the result of a condition that I did not consider when the code was changed for pull request #14665.

I believe that 2 sets of changes need to be made to fix this issue.

Please see the annotated screenshot of pull request #14665 listed below

Fix__14596_-fixes_p-dropdown_logic_for_selectedOption_and_label_by_rosenthalj·Pull_Request__14665·_primefaces_primeng

@Cr3aHal0
Copy link
Contributor

Cr3aHal0 commented Feb 6, 2024

Hi rosenthalj,

I'll be investigating your suggestion, I did not encountered any incorrect behaviour while testing the change but i'll retry :)

@rosenthalj
Copy link
Contributor

Cr3aHal0,

When testing I would recommend that you try the following "filtering" cases:

  1. A test case similar to the last video in pull request Fix #14596 - fixes p-dropdown logic for selectedOption and label #14665 comments.
    --- set options 0, 1, 2
    --- select 0
    --- enter 1 in the filter
  2. A test case that enters a value that doesn't match any option
    --- set options 0, 1, 2
    --- select 0
    --- enter "A" in the filter

@cetincakiroglu cetincakiroglu self-assigned this Feb 7, 2024
@cetincakiroglu cetincakiroglu added this to the 17.6.0 milestone Feb 7, 2024
@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 Feb 7, 2024
@cetincakiroglu cetincakiroglu removed their assignment Feb 7, 2024
@cetincakiroglu
Copy link
Contributor

Fixed in #14719

@eduardheller89
Copy link
Contributor Author

Thank you for being fast with the issue. Thats great

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.

4 participants