SaturnTeam / saturn-datepicker

Angular Material Datepicker with range selection
MIT License
278 stars 110 forks source link

Problem when typing the date in the input #168

Closed aminesafi8 closed 3 years ago

aminesafi8 commented 3 years ago

Hi folks,

In my angular 9 project I am using sat-datepicker, my dates patterns are day/month/year It works fine if I select 2 dates from the datepicker but if I edit one of them or I write them manually in the input field, the input will be invalid since there is a problem with validating the date. Example : I select from the date picker 2 dates (01/03/2021 and 11/03/2021) respectively 1 of March and 11 of March 2021 my input will be something like this

Capture

If I try to edit the second date for example from 11 to 15, I'm getting a invalid form control, I'm printing the error in a <p> tag image

If I reverse the day and the month (from 01/03/2021 to 03/01/2021 and from 15/03/2021 to 03/15/2021) it will work but it will take the day as a month which will cause wrong filtering criteria so the problem is dates like that MM/DD/YYYY are valid but DD/MM/YYYY aren't. I tried a lot of solutions on stackoverflow and on Github but it is still not working.

Thanks in advance.

aminesafi8 commented 3 years ago

I fixed the issue by importing the DateAdapter from 'saturn-datepicker' and not from 'angular-calendar' and by adding these two lines in the providers {provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]}, {provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS},