Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
acharyaks90 opened this issue Mar 16, 2020 · 5 comments
Closed

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

acharyaks90 opened this issue Mar 16, 2020 · 5 comments

Comments

@acharyaks90
Copy link

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
Copy link
Author

@acharyaks90
Copy link
Author

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"/>

Last 3 Month Last 6 Month Reset

<button (click)="changeDefaultMonthDynamically()">change DefaultMonth Dynamically

`

@kekeh
Copy link
Owner

kekeh commented Mar 16, 2020

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
Copy link
Owner

kekeh commented Mar 16, 2020

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.

@kekeh kekeh closed this as completed Mar 16, 2020
@acharyaks90
Copy link
Author

@kekeh Thank very much quick support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants