Skip to content
This repository was archived by the owner on Jan 22, 2018. It is now read-only.

Commit d0b96f3

Browse files
author
Kamil Kisiela
committed
Add datepicker with date range and filtering
1 parent 112bac7 commit d0b96f3

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [Unreleased]
6+
### Added
7+
- datepicker with date range and filtering _(currently in angular-material 1.0_RC4)_
8+
59
## [0.2.0] - 2015-11-17
610
### Added
711
- Support for textarea with cols and rows
@@ -37,6 +41,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3741

3842
## 0.0.1 - 2015-11-06
3943

44+
[Unreleased]: https://github.com/kamilkisiela/meteor-angular-formly-templates-material/compare/v0.2.0...HEAD
4045
[0.2.0]: https://github.com/kamilkisiela/meteor-angular-formly-templates-material/compare/v0.1.0...v0.2.0
4146
[0.1.0]: https://github.com/kamilkisiela/meteor-angular-formly-templates-material/compare/v0.0.4...v0.1.0
4247
[0.0.4]: https://github.com/kamilkisiela/meteor-angular-formly-templates-material/compare/v0.0.3...v0.0.4
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var {SetModule} = angular2now;
2+
3+
SetModule('formlyMaterial')
4+
.config((formlyConfigProvider, formlyMaterialProvider) => {
5+
6+
formlyConfigProvider.setType({
7+
name: 'datepicker',
8+
templateUrl: formlyMaterialProvider.templateUrl('lib/client/types/datepicker/datepicker.ng.html'),
9+
wrapper: ['mdMessages'],
10+
defaultOptions: {
11+
ngModelAttrs: {
12+
placeholder: {attribute: 'md-placeholder'}
13+
}
14+
},
15+
apiCheck: (check) => ({
16+
templateOptions: {
17+
placeholder: check.string.optional,
18+
minDate: check.instanceOf(Date).optional,
19+
maxDate: check.instanceOf(Date).optional,
20+
filterDate: check.func.optional
21+
}
22+
})
23+
});
24+
25+
formlyConfigProvider.templateManipulators.preWrapper.push((template, options) => {
26+
if (angular.isDefined(options.templateOptions.minDate)
27+
|| angular.isDefined(options.templateOptions.maxDate)
28+
|| angular.isDefined(options.templateOptions.filterDate)) {
29+
30+
const dateConfig = {
31+
min: options.templateOptions.minDate || undefined,
32+
max: options.templateOptions.maxDate || undefined,
33+
filter: options.templateOptions.filterDate || undefined
34+
};
35+
const node = document.createElement('div');
36+
37+
node.innerHTML = template;
38+
const datepickerNode = node.querySelector('md-datepicker');
39+
40+
if (datepickerNode) {
41+
if (dateConfig.min) {
42+
datepickerNode.setAttribute('md-min-date', 'to.minDate');
43+
}
44+
if (dateConfig.max) {
45+
datepickerNode.setAttribute('md-max-date', 'to.maxDate');
46+
}
47+
if (dateConfig.filter) {
48+
datepickerNode.setAttribute('md-date-filter', 'to.filterDate');
49+
}
50+
}
51+
return node.innerHTML;
52+
}
53+
54+
55+
return template;
56+
});
57+
58+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<md-datepicker ng-model="model[options.key]"></md-datepicker>
3+
</div>

package.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ Package.onUse(function (api) {
8686

8787
// textarea
8888
'lib/client/types/textarea/textarea.js',
89-
'lib/client/types/textarea/textarea.ng.html'
89+
'lib/client/types/textarea/textarea.ng.html',
90+
91+
// datepicker
92+
'lib/client/types/datepicker/datepicker.js',
93+
'lib/client/types/datepicker/datepicker.ng.html'
9094

9195
], client);
9296

0 commit comments

Comments
 (0)