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

fixes the validation for date picker in IE #10015

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/components/datepicker/js/datepickerDirective.js
Expand Up @@ -571,9 +571,31 @@
this.ngModelCtrl.$setValidity('valid', date == null);
}

var input = this.inputElement.value;
var parsedDate = this.locale.parseDate(input);

if (!this.isInputValid(input, parsedDate) && this.ngModelCtrl.$valid) {
this.ngModelCtrl.$setValidity('valid', date == null);
}

angular.element(this.inputContainer).toggleClass(INVALID_CLASS, !this.ngModelCtrl.$valid);
};

/**
* Check to see if the input is valid as the validation should fail if the model is invalid
*
* @param {String} inputString
* @param {Date} parsedDate
* @return {boolean} Whether the input is valid
*/
DatePickerCtrl.prototype.isInputValid = function (inputString, parsedDate) {
return inputString == '' || (
this.dateUtil.isValidDate(parsedDate) &&
this.locale.isDateComplete(inputString) &&
this.isDateEnabled(parsedDate)
);
};

/** Clears any error flags set by `updateErrorState`. */
DatePickerCtrl.prototype.clearErrorState = function() {
this.inputContainer.classList.remove(INVALID_CLASS);
Expand All @@ -598,11 +620,7 @@

// An input string is valid if it is either empty (representing no date)
// or if it parses to a valid date that the user is allowed to select.
var isValidInput = inputString == '' || (
this.dateUtil.isValidDate(parsedDate) &&
this.locale.isDateComplete(inputString) &&
this.isDateEnabled(parsedDate)
);
var isValidInput = this.isInputValid(inputString, parsedDate);

// The datepicker's model is only updated when there is a valid input.
if (isValidInput) {
Expand Down