This is a migrated thread and some comments may be shown as answers.

Datepicker Component's min field bug

2 Answers 350 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
EGrop
Top achievements
Rank 1
EGrop asked on 03 Oct 2018, 11:08 AM

Hi guys!

I encountered a very strange behavior by the DatePickerComponent because as I discovered, the component's min field isn't resetting properly upon the OnDestroy lifecycle.

Reproduction code: https://stackblitz.com/edit/angular-22wree

Reproduction steps:

  1. Set the first date to 2018.10.10.
  2. Set the second date to 2018.10.10.
  3. Set the first date to 2018.10.15.
  4. Modify the second date (to trigger the minError validation) to 2018.10.14.
  5. Now press the Reset button twice.

And here comes the bug. If you set the first date to 2018.10.05 and the second date to 2018.10.06, the second date triggers the minError validation error with the first min date and not with the actual date.

These dates are just examples for a fast reproduction but in short you need to trigger the minError validation twice on the second date field: First just normally, and the second must occur after the show/hide mechanism.

I didn't test this for the max field.

2 Answers, 1 is accepted

Sort by
0
EGrop
Top achievements
Rank 1
answered on 04 Oct 2018, 08:07 AM

The OnDestroy lifecycle was just a tip in my earlier post, which wasn't mentioned. At last but not least if this possible bug is reported to the wrong place, then sorry for this little inconvenience.

 

Sorry for the possible confusions.

Thank You Very Much for your time in advance!

0
Accepted
Dimiter Topalov
Telerik team
answered on 05 Oct 2018, 07:21 AM
Hello,

Thank you for the runnable demo and the detailed explanation. This indeed seems like a bug, but actually is an issue with Angular itself and how it handles validators and value accessors when there is a form group binding and the input is destroyed and recreated (for example via *ngIf):

https://github.com/angular/angular/issues/7970#issuecomment-228624899

There are two solutions that come to mind - either hide/show the DatePicker via CSS (as opposed to destroying the whole component), or recreate the FormGroup replacing it with a new instance each time the inputs are recreated.

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
EGrop
Top achievements
Rank 1
Answers by
EGrop
Top achievements
Rank 1
Dimiter Topalov
Telerik team
Share this question
or