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: onBlur is been called on selection, without lost focus, and before onChange #14128

Closed
lixaotec opened this issue Nov 15, 2023 · 4 comments
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@lixaotec
Copy link

Describe the bug

Dear Fellows,

It seems to me that onBlur shoud not be called on option selection in pDropDown, and when an options is chosen, the control has not lost focus yet, and p-dropdown is calling onBlur at that time..
And in my case it seems to be called moments before the data (option) actually has been changed (what fires onChange), and I have a validation which occurs on onBlur.

The wordaround (very ugly in fact) i found is to have a timer to wait 100-200ms in onBlur step to wait for the option be filled so I can dispatch a validation.

What do you think?
Should p-Dropdown deal with it, or simply dont dispatch onBlur if it has not lost focus?

Thanks in advance.

Environment

angular v16

Reproducer

No response

Angular version

v16.2

PrimeNG version

v16.6.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

lastest

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@lixaotec lixaotec 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 15, 2023
@cetincakiroglu
Copy link
Contributor

Hi,

Component fires onBlur event after the input loses focus. Check the example https://stackblitz.com/edit/piyadq?file=src%2Fapp%2Fdemo%2Fdropdown-basic-demo.html,src%2Fapp%2Fdemo%2Fdropdown-basic-demo.ts

@lixaotec
Copy link
Author

Dear @cetincakiroglu ,

Thanks for promptly replaying.

Sure it does fires after the input loses focus.

The question it is also firing before losing focus too.. and if you subscribe to onChange, you´ll notice that onChange is fired before onBlur, which leads to confusion. That´s because when an item is selected , there´s no focus losing yet.

So its firing onBlur when it wasnt supposed to, and by that, onChange ends calling after it.

Blur is a widely event trigger to dispatch validation. If i trigger it before selected item is ready, will end up on false positive error message.

https://stackblitz.com/edit/piyadq-iicqbz?file=src%2Fapp%2Fdemo%2Fdropdown-basic-demo.ts

Agreed?

@cetincakiroglu
Copy link
Contributor

Thanks for explanation and the example, I'll check it 👍🏻

@cetincakiroglu cetincakiroglu added this to the 16.8.0 milestone Nov 16, 2023
@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 Nov 17, 2023
@dimitrisx26
Copy link

dimitrisx26 commented Jun 6, 2024

Hello,

I noticed that this bug has reappeared in PrimeNG version 17.18

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

No branches or pull requests

3 participants