diff --git a/src/datepickerPopup/popup.js b/src/datepickerPopup/popup.js index 02c0e88a1c..6b28e35de8 100644 --- a/src/datepickerPopup/popup.js +++ b/src/datepickerPopup/popup.js @@ -72,6 +72,13 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ } } }); + $attrs.$observe('altInputFormats', function(value, oldValue) { + var newAltInputFormats = angular.isDefined(value) ? $scope.$parent.$eval(value) : altInputFormats; + + if (newAltInputFormats !== altInputFormats) { + altInputFormats = newAltInputFormats; + } + }); } if (!dateFormat) { diff --git a/src/datepickerPopup/test/popup.spec.js b/src/datepickerPopup/test/popup.spec.js index 227fdb3596..501f396553 100644 --- a/src/datepickerPopup/test/popup.spec.js +++ b/src/datepickerPopup/test/popup.spec.js @@ -1514,7 +1514,8 @@ describe('datepicker popup', function() { describe('attribute `alt-input-formats`', function() { beforeEach(function() { $rootScope.date = new Date('November 9, 1980'); - var wrapElement = $compile('
')($rootScope); + $rootScope.altInputFormats = ['M!/d!/yyyy']; + var wrapElement = $compile('
')($rootScope); $rootScope.$digest(); assignElements(wrapElement); }); @@ -1532,6 +1533,17 @@ describe('datepicker popup', function() { changeInputValueTo(inputEl, '11/8/1980'); expect(selectedElementIndex()).toEqual(13); }); + + it('changes alternate input formats', function() { + $rootScope.altInputFormats = ['yyyy-M!-d!']; + $timeout(function() { + changeInputValueTo(inputEl, '2017-08-30'); + + expect($rootScope.date.getFullYear()).toEqual(2017); + expect($rootScope.date.getMonth()).toEqual(7); + expect($rootScope.date.getDate()).toEqual(30); + }, 0); + }); }); });