Search code examples
javascriptangulardatepicker

ng2-date-picker - After typing date in datepicker input we can see that date in calendar, but after selecting it from calendar it deletes from input


After typing date in datepicker input we can see that date in calendar, but after we type that date and it shows in calendar, we select it from calendar but it deletes from input. I guess it is problem with same dates, so if you type some date and then select that same date from calendar it somehow repeal. Someone knows how to solve this problem? We need this date even if it is the same one from typing.

file.html
<dp-date-picker
                    id="search_dateFrom"
                    class="dp-date-picker"
                    theme="dp-material"
                    mode="day"
                    placeholder="DD.MM.GGGG."
                    [config]="this.config"
                    [(ngModel)]="datesArray['dateFrom']"
                    (onSelect)="checkValue($event)"
                    (ngModelChange)="onChangeSearch2($event)"
                  >
                  </dp-date-picker>

file.ts

onChangeSearch2(event)
  {
    console.log('event',event);
  }

checkValue(event){
    if (event.type == 'selection')
      if(event.date._i)
      {
        this.datesArray['dateFrom']=event.date._i;
      }

  }

after typing


Solution

  • Might as well post a proper answer.

    According to the docs it seems to be the default behavior that dates can be both selected and unselected. Fortunately, there is a property called unSelectOnClick which if set to false, prevents the user from unselecting dates.