kekeh / angular-mydatepicker

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

In Inline mode not able set date month year or default view #33

Closed acharyaks90 closed 4 years ago

acharyaks90 commented 4 years ago

In Inline mode not able set date month year or default view to back to some date dynamically for single date mode I had tried using default month it work for very first time but then it doesn't work.

It works for non inline mode. in default view not able to understand what type of value is to be given i tried with date and other please give example of that also.

acharyaks90 commented 4 years ago

https://stackblitz.com/edit/angular-ngmydatepicker?embed=1&file=src/app/app.component.ts

acharyaks90 commented 4 years ago

Here is stackblitz code attached

https://stackblitz.com/edit/angular-ngmydatepicker

` myDpOptions: IAngularMyDpOptions = { dateRange: false, dateFormat: 'dd.mm.yyyy', inline:true // other options are here... };

myDateInit: boolean = true; model: IMyDateModel = null;

defaultMonth: IMyDefaultMonth ;

constructor(private cd : ChangeDetectorRef){

}

ngOnInit() {

    this.model = {isRange: false, singleDate: {date: { 
                                                        year: 2020, 
                                                        month: 4, 
                                                        day: 14 
                                                      }}};

this.defaultMonth = {
  defMonth:'01/2020'
}

}

trigLast(tenure){ console.log(tenure) if(tenure=='rest'){ this.defaultMonth = { defMonth:'03/2020'} this.model = {isRange: false, singleDate: {date: { year: 2020, month: 4, day: 14 }}}; this.model = JSON.parse(JSON.stringify( this.model )); this.model.singleDate ={date: { year: 2020, month: 4, day: 14 }} }else if(tenure=='three'){ this.defaultMonth = { defMonth:'01/2020'} this.model = {isRange: false, singleDate: {date: { year: 2020, month: 1, day: 14 }}}; this.model = JSON.parse(JSON.stringify( this.model )); this.model.singleDate ={date: { year: 2020, month: 1, day: 14 }} }else if(tenure=='six'){ this.defaultMonth = { defMonth:'09/2019'} this.model = {isRange: false, singleDate: {date: { year: 2019, month: 9, day: 14 }}}; this.model = JSON.parse(JSON.stringify( this.model )); this.model.singleDate ={date: { year: 2019, month: 9, day: 14 }} } this.myDpOptions = JSON.parse(JSON.stringify(this.myDpOptions )) }

changeDefaultMonthDynamically(): void {

    this.defaultMonth = {
        defMonth: '09/2020'
    };

}

`

Html `

<input class="input-box" placeholder="Click to select a date" angular-mydatepicker name="mydate" (click)="dp.toggleCalendar()" [(ngModel)]="model" [options]="myDpOptions" [defaultMonth]="defaultMonth"

dp="angular-mydatepicker"/>

`
kekeh commented 4 years ago

Hello @acharyaks90

You can set default view in options as follows:

  import {IAngularMyDpOptions, DefaultView} from "angular-mydatepicker";

  myDatePickerOptions: IAngularMyDpOptions = {
    defaultView: DefaultView.Date,
    or
    defaultView: DefaultView.Month,
    or
    defaultView: DefaultView.Year,
  }
kekeh commented 4 years ago

I fixed this issue. Try version 0.5.2.

If you set the defaultMonth and set a date to the model at the same time the model value overrides the defaultMonth value. In this case the visible month is same what are the month and the year in the value of model.

The defaultMonth works ok without selected date.

acharyaks90 commented 4 years ago

@kekeh Thank very much quick support.