indrimuska / angular-moment-picker

Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
http://indrimuska.github.io/angular-moment-picker/
MIT License
527 stars 229 forks source link

_d and _i are different from each other and are not the date I picked #299

Open CJDennis opened 3 years ago

CJDennis commented 3 years ago

This is my control:

<input class="form-control"
       placeholder="Select a date and time"
       moment-picker="hmrCtrl.extra.nextAppointment"
       locale="en-au"
       format="LL, LT"
       min-date="dateOptions.minDate"
       max-date="dateOptions.nextApp"
       ng-model="hmrCtrl.extra.nextAppointment"
       ng-model-options="{ updateOn: 'blur' }">

I picked a date and time in March 2020 and the Moment object hmrCtrl.extra.nextAppointment got set as follows:

Moment {_isAMomentObject: true, _i: Mon May 04 2020 23:59:59 GMT+1000 (Australian Eastern Standard Time), _isUTC: false, _pf: {…}, _locale: Locale, …}
_d: Mon Nov 04 2019 00:00:00 GMT+1100 (Australian Eastern Daylight Time) {}
_i: Mon May 04 2020 23:59:59 GMT+1000 (Australian Eastern Standard Time) {}
...

_d ends up containing the value of min-date and _i ends up containing the value of max-date. hmrCtrl.extra.nextAppointment is initially undefined. The console log has some errors:

angular.js:13920 Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: item in row track by item.index, Duplicate key: null, Duplicate value: {"index":null,"label":"Invalid date","year":null,"month":null,"date":null,"hour":null,"minute":null,"class":"disabled","selectable":false}
http://errors.angularjs.org/1.5.8/ngRepeat/dupes?p0=item%20in%20row%20track%20by%20item.index&p1=null&p2=%7B%22index%22%3Anull%2C%22label%22%3A%22Invalid%20date%22%2C%22year%22%3Anull%2C%22month%22%3Anull%2C%22date%22%3Anull%2C%22hour%22%3Anull%2C%22minute%22%3Anull%2C%22class%22%3A%22disabled%22%2C%22selectable%22%3Afalse%7D
    at angular.js:68
    at ngRepeatAction (angular.js:29821)
    at $watchCollectionAction (angular.js:17385)
    at Scope.$digest (angular.js:17524)
    at ChildScope.$apply (angular.js:17790)
    at HTMLTableCellElement.<anonymous> (angular.js:25890)
    at HTMLTableCellElement.dispatch (jquery.js:4435)
    at HTMLTableCellElement.r.handle (jquery.js:4121)

I can't use the control again until I delete the date-time string in it because it just says "Invalid date" for every heading. This happens whether I set a default date-time or not. After I delete the first date-time string it works as expected.

How can I fix this error?