components icon indicating copy to clipboard operation
components copied to clipboard

mat-datepicker: valueChange fires without blur event with `updateOn: 'blur'` set

Open lautarobock opened this issue 4 years ago • 6 comments

Reproduction

Use StackBlitz to reproduce your issue: https://stackblitz.com/edit/angular-6qr4ut?file=angular.json

Steps to reproduce:

  1. Type a valid date in the box starting with '0' (zero)
  2. Wihtout blur start to delete char by char from the end
  3. Delete the all chars until the last one (zero char from step 1)

Expected Behavior

Nothing should happen, since the focus still in the box

Actual Behavior

valueChanges event is fired. The changes will be pushed into an array and displayed in the page

Environment

  • Angular: 9
  • CDK/Material: 9
  • Browser(s): Chrome (but should work in others)
  • Operating System (e.g. Windows, macOS, Ubuntu): windows
  • Ivy disabled
  • IMPORTANT you have to use MatMomentDateModule

lautarobock avatar Jun 11 '20 19:06 lautarobock

Confirmed that the date input appears to be emitting superfluous events here any time the input contains just 0

jelbourn avatar Jun 11 '20 21:06 jelbourn

fix(material/datepicker) : value change without blur when the date starts with 0

As we see the behaviour of date picker it never adds any 0's at the start of a month or day which are single digits. May be we put the validations for the input field so that it acts as same and dosent allow the user to add zeroes at the start??? thoughts: @lautarobock @jelbourn @sandikbarr

Fixes angular#19613

sahilmore-git avatar Aug 20 '21 09:08 sahilmore-git

@sahilmore-git But that will be a workaround. I think this behavior is a bug, those events never should be triggered

lautarobock avatar Aug 20 '21 12:08 lautarobock

Yes I totally agree with you @lautarobock but I just found out that even if we add a character like 'a' or 'b' any character in an empty input field the event gets triggered even if it's still in focus. That's a new issue I guess. :(

sahilmore-git avatar Aug 21 '21 17:08 sahilmore-git

We are now facing this issue as well. Whenever we attempt to enter in the date manually it instantly triggers the form value change event even those we set the form field as updateOn: 'blur'

taylordevereaux avatar Jul 19 '22 18:07 taylordevereaux

Same goes for updateOn: 'submit'

richardsengers avatar Jul 20 '22 12:07 richardsengers

Is there anyone working on this one ? I can try to fix it.

ZeroGDrive avatar Aug 04 '22 17:08 ZeroGDrive

Hey @jelbourn this bug is not happening anymore, i believe this issue need to be closed. Btw @lautarobock if still happening with you pipe(distinctUntilChanged()) should be help you

viniciusschuelter avatar Aug 09 '22 20:08 viniciusschuelter

@viniciusschuelter thanks, will close; anyone tracking this issue feel free to reopen with a reproduction if it's still occurring in the latest version

jelbourn avatar Aug 12 '22 22:08 jelbourn

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.