Skip to content

Commit 89d2102

Browse files
committed
Fix defect where configuration on scope (in the form of a function or property) were not being picked up. Updated demo page to show how to get configuration from the scope.
1 parent 0ce65e8 commit 89d2102

File tree

5 files changed

+106
-5
lines changed

5 files changed

+106
-5
lines changed

demo/demo-controller.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,15 @@ angular.module('demo.demoController', [])
5858
console.log(index);
5959
$dates[index].selectable = false;
6060
};
61+
62+
$scope.config = {
63+
datetimePicker: {
64+
startView: 'year'
65+
}
66+
};
67+
68+
$scope.configFunction = function configFunction() {
69+
return {startView: 'month'};
70+
};
6171
}
6272
]);

demo/index.html

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ <h3>Show / hide with check box</h3>
214214
</div>
215215

216216
<div class="row">
217-
218-
219217
<div class="col-sm-6">
220218
<h3>Embedded calendar</h3>
221219

@@ -258,6 +256,35 @@ <h3>Embedded calendar form integration</h3>
258256
</div>
259257
</div>
260258

259+
260+
<div class="row">
261+
<div class="col-sm-6">
262+
<h3>Embedded calendar with property configuration</h3>
263+
264+
<p><code>data-datetimepicker-config="config.datetimePicker"</code></p>
265+
<p>which returns <code>{ startView: 'year' }</code></p>
266+
267+
<div class="well">
268+
<p>Formatted Date: {{ data.embeddedPropertyConfig | date:'yyyy-MM-dd h:mm a' }}</p>
269+
270+
<datetimepicker data-ng-model="data.embeddedPropertyConfig" data-datetimepicker-config="config.datetimePicker" ></datetimepicker>
271+
</div>
272+
</div>
273+
<div class="col-sm-6">
274+
<h3>Embedded calendar with function configuration</h3>
275+
276+
<p><code>data-datetimepicker-config="configFunction()"</code></p>
277+
<p>which returns <code>{ startView: 'month' }</code></p>
278+
279+
<div class="well">
280+
<p>Formatted Date: {{ data.embeddedFunctionConfig | date:'yyyy-MM-dd h:mm a' }}</p>
281+
282+
<datetimepicker data-ng-model="data.embeddedFunctionConfig" data-datetimepicker-config="configFunction()" ></datetimepicker>
283+
</div>
284+
</div>
285+
286+
</div>
287+
261288
<div class="row">
262289
<div class="col-sm-6">
263290
<h3>ng-repeat with drop-down using text link</h3>

src/js/datetimepicker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ angular.module('ui.bootstrap.datetimepicker', [])
127127
var directiveConfig = {};
128128

129129
if (attrs.datetimepickerConfig) {
130-
directiveConfig = scope.$eval(attrs.datetimepickerConfig);
130+
directiveConfig = scope.$parent.$eval(attrs.datetimepickerConfig);
131131
}
132132

133133
var configuration = {};

test/configuration/beforeRender.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
/**
44
* @license angular-bootstrap-datetimepicker
5-
* (c) 2013 Knight Rider Consulting, Inc. http://www.knightrider.com
5+
* (c) 2013-2014 Knight Rider Consulting, Inc. http://www.knightrider.com
66
* License: MIT
77
*/
88

99
/**
1010
*
1111
* @author Dale "Ducky" Lotts
12-
* @since 11/8/2013
12+
* @since 11/8/2014
1313
*/
1414
describe('beforeRender', function () {
1515
'use strict';
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*globals ddescribe, describe, beforeEach, it, expect, module, inject, jQuery, moment, spyOn */
2+
3+
/**
4+
* @license angular-bootstrap-datetimepicker
5+
* (c) 2014 Knight Rider Consulting, Inc. http://www.knightrider.com
6+
* License: MIT
7+
*/
8+
9+
/**
10+
*
11+
* @author Dale "Ducky" Lotts
12+
* @since 11/15/2014
13+
*/
14+
15+
describe('dateimePickerConfig', function () {
16+
'use strict';
17+
var $rootScope, $compile;
18+
19+
beforeEach(module('ui.bootstrap.datetimepicker'));
20+
21+
beforeEach(inject(function (_$compile_, _$rootScope_) {
22+
moment.locale('en');
23+
$compile = _$compile_;
24+
$rootScope = _$rootScope_;
25+
}));
26+
27+
28+
describe('retrieves information from', function () {
29+
it('function on scope', function () {
30+
31+
var $scope = $rootScope.$new();
32+
$scope.date = moment('2014-11-15T00:00:00.000').toDate();
33+
$scope.configFunction = function configFunction() {
34+
return {startView: 'month'};
35+
};
36+
37+
spyOn($scope, 'configFunction').and.callThrough();
38+
39+
var element = $compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="configFunction()" ></datetimepicker>')($scope);
40+
$scope.$digest();
41+
42+
expect(jQuery('.switch', element).text()).toBe('2014');
43+
expect($scope.configFunction).toHaveBeenCalled();
44+
});
45+
46+
it('property on scope', function () {
47+
48+
var $scope = $rootScope.$new();
49+
$scope.date = moment('2014-11-15T00:00:00.000').toDate();
50+
$scope.config = {
51+
datetimePicker: {
52+
startView: 'year'
53+
}
54+
};
55+
56+
spyOn($scope, 'config').and.callThrough();
57+
58+
var element = $compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="config.datetimePicker" ></datetimepicker>')($scope);
59+
$scope.$digest();
60+
61+
expect(jQuery('.switch', element).text()).toBe('2010-2019');
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)