Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

uib-datepicker using new data() on "ngModelCtrl.$modelValue" in UibDatepickerController causes error in Internet Explorer #5865

Closed
FFelling opened this issue Apr 29, 2016 · 3 comments

Comments

@FFelling
Copy link

FFelling commented Apr 29, 2016

We use uib-datepicker with popup where we allow the user the enter a date manually.
The dateformat ('d MMMM y') has a year with a single y so a single-digit year can also be entered as a year.

On load we set today's date with a four-digit year. When you change the year to have only 2 digits the datepicker renders with all null and nan values, see attached screenshot. This happens only on Internet Explorer (tested on 11). Chrome and FireFox do not have this issue.

Plunker: http://plnkr.co/edit/sGbHK8N4C0EAmpyT9FB9?p=preview

Reproduce:

  1. Open the plnkr in IE;
  2. Place the cursor in the textbox at the end of the date;
  3. Press backspace twice to create the 2-digit your;
  4. Click on the icon to display the datepicker-popup.
  • Angular: 1.5.5
  • UIBS: 1.3.2
  • Bootstrap: 3.3.6

datepickernan

In the "this._init" function in "UibDatepickerController" the following lines cause the error in IE.

this.activeDate = ngModelCtrl.$modelValue ?
  dateParser.fromTimezone(new Date(ngModelCtrl.$modelValue), ngModelOptions.timezone) :
  dateParser.fromTimezone(new Date(), ngModelOptions.timezone);

We have modified these like below to fix the issue.

if (ngModelCtrl.$modelValue) {
  var inputDate = new Date(ngModelCtrl.$viewValue),
      isInputValid = !isNaN(inputDate);

  if (isInputValid) {
    this.activeDate = dateParser.fromTimezone(inputDate, ngModelOptions.timezone);
  }
}
@wesleycho
Copy link
Contributor

What looks like is actually happening is that IE is incorrectly returning that !isNaN(invalidDate) is true. We need to fix this check, if a more reliable check can be found.

@wesleycho
Copy link
Contributor

I wonder why new Date() in the $scope.today function is invalid for me - this problem appears for me in Windows 8.1 IE11.

@wesleycho
Copy link
Contributor

So I found out what happened - calling new Date(validDateIEThinksIsInvalid) results in an invalid date.

I guess I'm ok with a hack being added for this IE edge case, and will open a PR shortly.

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

Successfully merging a pull request may close this issue.

3 participants