-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoform-bs-daterangepicker.js
58 lines (50 loc) · 1.5 KB
/
autoform-bs-daterangepicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var range = {};
AutoForm.addInputType('bootstrap-daterangepicker', {
template: 'afBootstrapDateRangePicker',
valueOut: function () {
if (range.startDate && range.endDate)
return [range.startDate.toDate(), range.endDate.toDate()];
else
return [];
},
valueConverters: {
"dateArray": function (val) {
if (range.startDate && range.endDate)
return [range.startDate.toDate(), range.endDate.toDate()];
else
return [];
}
}
});
Template.afBootstrapDateRangePicker.helpers({
atts: function addFormControlAtts() {
var atts = _.clone(this.atts);
// Add bootstrap class
atts = AutoForm.Utility.addClass(atts, "form-control");
delete atts.dateRangePickerOptions;
return atts;
},
dateRangePickerValue: function() {
return this.atts['dateRangePickerValue'];
}
});
Template.afBootstrapDateRangePicker.rendered = function () {
var $input = this.$('input');
var data = this.data;
if (data.atts.dateRangePickerOptions.startDate)
range.startDate = data.atts.dateRangePickerOptions.startDate;
if (data.atts.dateRangePickerOptions.endDate)
range.endDate = data.atts.dateRangePickerOptions.endDate;
// instanciate datepicker
$input.daterangepicker(
data.atts.dateRangePickerOptions,
function(start, end) {
range.startDate = start;
range.endDate = end;
}
);
};
Template.afBootstrapDateRangePicker.destroyed = function () {
var $input = this.$('input');
$input.daterangepicker('remove');
};