kekeh / angular-mydatepicker

Angular datepicker and date range picker :date:
https://kekeh.github.io/angular-mydatepicker/
MIT License
1 stars 11 forks source link

how i can reflect default value of date from input to datepicker? #53

Closed gmengi closed 4 years ago

gmengi commented 4 years ago

After selecting the date from the date picker, it reflects the value in input but if I have a default value in input that is not reflecting into date picker.

kekeh commented 4 years ago

Type value to the input box. It must be in the same format that is given in dateFormat option.

Try here: https://kekeh.github.io/angular-mydatepicker/

The first date picker on the page. Type value 10.7.2020 into input box and the open calendar. Date 10.7.2020 is selected on calendar.

kekeh commented 4 years ago

Use ngModel to set default date like below.

  <input class="input-box" angular-mydatepicker name="mydate" (click)="dp.toggleCalendar()" 
      [(ngModel)]="model" [options]="myDpOptions" #dp="angular-mydatepicker" 
      (dateChanged)="onDateChanged($event)"/>
this.model = {isRange: false, singleDate: {jsDate: new Date()}};
// or
this.model = {isRange: false, singleDate: {date: {year: 2020, month: 7, day: 10}}};

Examples:

gmengi commented 4 years ago

What? if I'm using inline mode with input and bind value with ngModel?

kekeh commented 4 years ago

Set input type to hidden like here: https://github.com/kekeh/angular-mydatepicker/blob/master/example/app/date-picker-inline/date-picker-inline.html#L10

kekeh commented 4 years ago

On this https://kekeh.github.io/angular-mydatepicker/ page the inline datepicker uses input type of hidden.

Code: https://github.com/kekeh/angular-mydatepicker/blob/gh-pages/src/app/dp-inline/dp-inline.component.html#L5

gmengi commented 4 years ago

In this case, I don't want to hide input. because I want to populate the selected date or default date in input as well.