hsuanxyz / ion2-calendar

📅 A date picker components for ionic2 /ionic3 / ionic4
https://hsuanxyz.github.io/demo/ion2-calendar/
MIT License
555 stars 277 forks source link

Enable previous day selection along with Month and Year Selection #140

Open DipakMahapurkar opened 6 years ago

DipakMahapurkar commented 6 years ago

ionic info: ionic/cli-utils : 1.19.1 ionic (Ionic CLI) : 3.19.1

global packages:

cordova (Cordova CLI) : 8.0.0 

local packages:

@ionic/app-scripts : 2.0.2
Cordova Platforms  : none
Ionic Framework    : ionic-angular 3.5.3

System:

Node  : v9.4.0
npm   : 5.6.0 
OS    : macOS High Sierra
Xcode : Xcode 9.2 Build version 9C40b 

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro

Current behavior:

First of all thanks for this lib. I am not able to select the previous day's. Options can't put within html ion-calendar tag.

<ion-calendar no-padding [(ngModel)]="date" (onChange)="onChange($event)" [type]="type" [format]="'DD-MM-YYYY'">
    </ion-calendar>

In .ts file

 date: string;
 type: 'string'; // 'string' | 'js-date' | 'moment' | 'time' | 'object'
 onChange($event) {
        console.log($event);
    }

onChange() getting below result.

Moment {_isAMomentObject: true, _i: 1519324200000, _isUTC: false, _pf: {…}, _locale: Locale, …}
_d:Fri Feb 23 2018 00:00:00 GMT+0530 (IST) {}
_i:1519324200000
_isAMomentObject:true
_isUTC:false
_isValid:true
_locale:Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", ordinal: ƒ, _dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/, …}
_pf:{empty: false, unusedTokens: Array(0), unusedInput: Array(0), overflow: -2, charsLeftOver: 0, …}
__proto__: Object

Also on ionViewDidLoad() printing null object, the line number in month.component.js:34 and the code is:

MonthComponent.prototype.writeValue = function (obj) {
        console.log(obj);
        if (Array.isArray(obj)) {
            this._date = obj;
        }
    };

Expected behavior:

I don't want the model for showing calendar view. Please refer below image calendar

Also there is provision for selecting the previous day along with month and year selection. onChnage the function return the date in string.

Thanks!!

abhinpai commented 6 years ago

Even i have the same issue, did you find the solution for this problem is yes than please let me know Thank you

hsuanxyz commented 6 years ago
$ npm i ion2-calendar@beta

image