Skip to content

Commit 0b78552

Browse files
committed
fix reactive value updating
1 parent e35c0be commit 0b78552

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

autoform-select2.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,21 @@ Template.afSelect2.helpers({
9797
});
9898

9999
Template.afSelect2.rendered = function () {
100+
var template = this;
101+
100102
// instanciate select2
101-
this.$('select').select2(this.data.atts.select2Options || {});
102-
};
103+
template.$('select').select2(template.data.atts.select2Options || {});
104+
105+
template.autorun(function () {
106+
var data = Template.currentData();
107+
108+
var values = [];
109+
_.each(data.items, function (item) {
110+
if (item.selected) {
111+
values.push(item.value);
112+
}
113+
});
103114

104-
Template.afSelect2.destroyed = function () {
105-
this.$('select').select2('destroy');
115+
template.$('select').select2("val", values);
116+
});
106117
};

themes/bootstrap3.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@ Template.afSelect2_bootstrap3.helpers({
2121
});
2222

2323
Template.afSelect2_bootstrap3.rendered = function () {
24+
var template = this;
25+
2426
// instanciate select2
25-
this.$('select').select2(this.data.atts.select2Options || {});
26-
};
27+
template.$('select').select2(template.data.atts.select2Options || {});
28+
29+
template.autorun(function () {
30+
var data = Template.currentData();
31+
32+
var values = [];
33+
_.each(data.items, function (item) {
34+
if (item.selected) {
35+
values.push(item.value);
36+
}
37+
});
2738

28-
Template.afSelect2_bootstrap3.destroyed = function () {
29-
this.$('select').select2('destroy');
39+
template.$('select').select2("val", values);
40+
});
3041
};

0 commit comments

Comments
 (0)