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

Commit

Permalink
fix(datepicker): evaluate show-weeks from datepicker-options
Browse files Browse the repository at this point in the history
Closes #1532
Closes #1563
  • Loading branch information
bekos authored and pkozlowski-opensource committed Jan 11, 2014
1 parent bc8d21c commit 92c1715
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
'ng-model': 'date',
'ng-change': 'dateSelection()'
});
var datepickerEl = angular.element(popupEl.children()[0]);
var datepickerEl = angular.element(popupEl.children()[0]),
datepickerOptions = {};
if (attrs.datepickerOptions) {
datepickerEl.attr(angular.extend({}, originalScope.$eval(attrs.datepickerOptions)));
datepickerOptions = originalScope.$eval(attrs.datepickerOptions);
datepickerEl.attr(angular.extend({}, datepickerOptions));
}

// TODO: reverse from dateFilter string to Date object
Expand Down Expand Up @@ -405,7 +407,7 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
if (attrs.showWeeks) {
addWatchableAttribute(attrs.showWeeks, 'showWeeks', 'show-weeks');
} else {
scope.showWeeks = datepickerConfig.showWeeks;
scope.showWeeks = 'show-weeks' in datepickerOptions ? datepickerOptions['show-weeks'] : datepickerConfig.showWeeks;
datepickerEl.attr('show-weeks', 'showWeeks');
}
if (attrs.dateDisabled) {
Expand Down
21 changes: 21 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,27 @@ describe('datepicker directive', function () {

});

describe('attribute `datepickerOptions`', function () {
var weekHeader, weekElement;
beforeEach(function() {
$rootScope.opts = {
'show-weeks': false
};
var wrapElement = $compile('<div><input ng-model="date" datepicker-popup datepicker-options="opts" is-open="true"></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);

weekHeader = getLabelsRow().find('th').eq(0);
weekElement = element.find('tbody').find('tr').eq(1).find('td').eq(0);
});

it('hides week numbers based on variable', function() {
expect(weekHeader.text()).toEqual('#');
expect(weekHeader).toBeHidden();
expect(weekElement).toBeHidden();
});
});

describe('toggles programatically by `open` attribute', function () {
beforeEach(inject(function() {
$rootScope.open = true;
Expand Down

0 comments on commit 92c1715

Please sign in to comment.