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

Commit

Permalink
fix(datepicker): Fix init-date not applying on datepicker-popup
Browse files Browse the repository at this point in the history
Fix of the init-date attribute for the datepicker-popup. The init-date attribute, when set in a datepicker-popup element, is now added to the datepicker element and in the datepicker-popup scope, so the datepicker element can retrieve the attribute value.
  • Loading branch information
thomaswinckell authored and wesleycho committed Mar 23, 2015
1 parent 2296115 commit c5b63de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
if (attrs.customClass){
datepickerEl.attr('custom-class', 'customClass({ date: date, mode: mode })');
}
if (attrs.initDate) {
scope.initDate = scope.$parent.$eval(attrs.initDate);
datepickerEl.attr('init-date', 'initDate');
}

function parseDate(viewValue) {
if (angular.isNumber(viewValue)) {
Expand Down
19 changes: 19 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,25 @@ describe('datepicker directive', function () {
expect($rootScope.mode).toBe('year');
});
});

describe('attribute `initDate`', function () {
var weekHeader, weekElement;
beforeEach(function() {
$rootScope.date = null;
$rootScope.initDate = new Date('November 9, 1980');
var wrapElement = $compile('<div><input ng-model="date" datepicker-popup init-date="initDate" is-open="true"></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
});

it('should not alter the model', function() {
expect($rootScope.date).toBe(null);
});

it('shows the correct title', function() {
expect(getTitle()).toBe('November 1980');
});
});
});

describe('with empty initial state', function () {
Expand Down

0 comments on commit c5b63de

Please sign in to comment.