-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathautoform-bs-timepicker.js
52 lines (45 loc) · 1.32 KB
/
autoform-bs-timepicker.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
/* global AutoForm, $ */
AutoForm.addInputType("bootstrap-timepicker", {
template: "afBootstrapTimepicker",
valueOut: function () {
if (this.val()) {
var val = this.timepicker('getTime');
return (val instanceof String) ? val : this.val();
}
},
valueConverters: {
"string": function (val) {
return val;
},
"stringArray": function (val) {
return [val];
}
}
});
Template.afBootstrapTimepicker.helpers({
atts: function addFormControlAtts() {
var atts = _.clone(this.atts);
// Add bootstrap class
atts = AutoForm.Utility.addClass(atts, "form-control");
delete atts.timePickerOptions;
return atts;
}
});
Template.afBootstrapTimepicker.rendered = function () {
var $input = this.data.atts.buttonClasses ? this.$('.input-group.time') : this.$('input');
var data = this.data;
// instanciate timepicker
$input.timepicker(data.atts.timePickerOptions);
// set and reactively update values
this.autorun(function () {
var data = Template.currentData();
// set field value
if (data.value instanceof String) {
$input.timepicker('setTime', data.value);
}
});
};
Template.afBootstrapTimepicker.destroyed = function () {
var $input = this.data.atts.buttonClasses ? this.$('.input-group.time') : this.$('input');
$input.timepicker('remove');
};