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

Commit

Permalink
feat(datepicker): add templateUrl support for pickers
Browse files Browse the repository at this point in the history
- Add support for custom template urls for `uibDaypicker`, `uibMonthpicker`, and `uibYearpicker`

Closes #4432
  • Loading branch information
filso authored and wesleycho committed Oct 14, 2015
1 parent 16dafd5 commit 1f65d87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
.directive('uibDaypicker', function() {
return {
replace: true,
templateUrl: 'template/datepicker/day.html',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/datepicker/day.html';
},
require: ['^?uibDatepicker', 'uibDaypicker', '^?datepicker'],
controller: 'UibDaypickerController',
link: function(scope, element, attrs, ctrls) {
Expand All @@ -473,7 +475,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
.directive('uibMonthpicker', function() {
return {
replace: true,
templateUrl: 'template/datepicker/month.html',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/datepicker/month.html';
},
require: ['^?uibDatepicker', 'uibMonthpicker', '^?datepicker'],
controller: 'UibMonthpickerController',
link: function(scope, element, attrs, ctrls) {
Expand All @@ -488,7 +492,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
.directive('uibYearpicker', function() {
return {
replace: true,
templateUrl: 'template/datepicker/year.html',
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/datepicker/year.html';
},
require: ['^?uibDatepicker', 'uibYearpicker', '^?datepicker'],
controller: 'UibYearpickerController',
link: function(scope, element, attrs, ctrls) {
Expand Down Expand Up @@ -1034,7 +1040,7 @@ angular.module('ui.bootstrap.datepicker')
var focusElement = function() {
self.element[0].focus();
};

$scope.$on('uib:datepicker.focus', focusElement);

$scope.keydown = function(evt) {
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 @@ -362,6 +362,25 @@ describe('datepicker directive', function() {
expect(element.html()).toBe('baz');
});

it('should support custom day, month and year templates', function() {
$templateCache.put('foo/day.html', '<div>day</div>');
$templateCache.put('foo/month.html', '<div>month</div>');
$templateCache.put('foo/year.html', '<div>year</div>');

$templateCache.put('foo/bar.html', '<div>' +
'<uib-daypicker template-url="foo/day.html"></uib-daypicker>' +
'<uib-monthpicker template-url="foo/month.html"></uib-monthpicker>' +
'<uib-yearpicker template-url="foo/year.html"></uib-yearpicker>' +
'</div>');

element = $compile('<uib-datepicker ng-model="date" template-url="foo/bar.html"></uib-datepicker>')($rootScope);
$rootScope.$digest();

var expectedHtml = '<div template-url="foo/day.html">day</div><div template-url="foo/month.html">month</div><div template-url="foo/year.html">year</div>';

expect(element.html()).toBe(expectedHtml);
});

it('should expose the controller in the template', function() {
$templateCache.put('template/datepicker/datepicker.html', '<div>{{datepicker.text}}</div>');

Expand Down

0 comments on commit 1f65d87

Please sign in to comment.