fetrarij / ngx-daterangepicker-material

Pure Angular 2+ date range picker with material design theme, a demo here:
https://fetrarij.github.io/ngx-daterangepicker-material/
MIT License
249 stars 252 forks source link

Selecting only start date set end date as invalid date #470

Open emmy29 opened 2 years ago

emmy29 commented 2 years ago

Versions

Describe the bug Selecting the start date only and clicking the Apply button convert the dates after the start date into NaN. In month section also shows invalid date.

To Reproduce Steps to reproduce the behavior:

  1. Select the start date
  2. Click on Apply button
  3. On input end date will show as an invalid date and if you open the date picker again all dates after the start date will display as NaN

Expected behavior If the end date is not selected it should have set end date same as the start date.

Screenshots image image image

Code <input type="text" name="FilterRange" readonly ngxDaterangepickerMd [dateLimit]="90" [locale]="{format: 'YYYY-MM-DD', separator: ' / '}" [ranges]="ranges" [showClearButton]="true" alwaysShowCalendars="true" keepCalendarOpeningWithRange="true" [(ngModel)]="filterRange" placeholder="Select Date Range"/>

DEVAN-lab commented 1 year ago

hello @emmy29 did you manage to select startDate only with ngx-daterangepicker-material? It seems to me not supported

emmy29 commented 1 year ago

hello @emmy29 did you manage to select startDate only with ngx-daterangepicker-material? It seems to me not supported

Hi Anis, I faced this issue after updating the Angular version, so the ngx-daterangepicker-material version was also updated. And the latest version was having this issue. I tried but didn't find anything related to this so I just downgraded the ngx-daterangepicker-material version to 4.0.1 and its working fine for now.

ivanferrer commented 1 year ago

I tried Installing the same version 4.0.1, however I still have this problem when I select only a day and not an interval. My angular is version 8.3.29. But I managed to solve the problem through a method that converts the data to a valid format.

formatDate(e) {
    if (e && e.startDate && e.endDate) {
        if(e.startDate == e.endDate) {
           e.startDate =new Date(e.startDate);
           e.endDate = new Date(e.endDate);
        }
        return {
          startDate: moment(e.startDate).toDate() || null,
          endDate: moment(e.endDate).toDate() || null
        }
      } else {
        return null;
      }
  }