From 3804eef13438b2febf6aa7f3de0afb9be1da666a Mon Sep 17 00:00:00 2001 From: "xue.zhang" Date: Wed, 30 Aug 2017 15:14:09 +0800 Subject: [PATCH] fix(datepickerPopup): altInputFormats(closes #6623) --- src/datepickerPopup/popup.js | 7 +++++++ src/datepickerPopup/test/popup.spec.js | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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); + }); }); });