-
Notifications
You must be signed in to change notification settings - Fork 2
/
materialize-chips.js
53 lines (51 loc) · 1.41 KB
/
materialize-chips.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
AutoForm.addInputType("materialize-chips", {
template: "afMaterializeChips",
valueIsArray: true,
valueOut: function() {
var ret = [];
var datas = this.material_chip('data')
if (datas) {
datas.forEach(function(data){
ret.push(data.tag);
});
}
return ret;
},
valueIn: function(val) {
var ret = [];
for (var i = 0; i < val.length; i++) {
ret.push({tag: val[i]});
};
return ret;
}
});
Template.afMaterializeChips.helpers({
atts: function() {
return _.omit(this.atts, 'placeholder', 'secondaryPlaceholder', 'autocompleteOptions');
}
})
Template.afMaterializeChips.onRendered(function() {
var template = this;
var params = this.data.atts;
template.autorun(function () {
var data = Template.currentData();
if (params && params.autocompleteOptions) {
template.$('.chips-autoform').material_chip({
data: data.value,
placeholder: params.placeholder,
secondaryPlaceholder: params.secondaryPlaceholder,
autocompleteOptions: {
limit: params.autocompleteOptions.limit,
minLength: params.autocompleteOptions.minLength,
data: params.autocompleteOptions.data()
}
});
} else {
template.$('.chips-autoform').material_chip({
data: data.value,
placeholder: params.placeholder,
secondaryPlaceholder: params.secondaryPlaceholder
});
}
});
});