File tree Expand file tree Collapse file tree 2 files changed +30
-8
lines changed
Expand file tree Collapse file tree 2 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -97,10 +97,21 @@ Template.afSelect2.helpers({
9797} ) ;
9898
9999Template . 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} ;
Original file line number Diff line number Diff line change @@ -21,10 +21,21 @@ Template.afSelect2_bootstrap3.helpers({
2121} ) ;
2222
2323Template . 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} ;
You can’t perform that action at this time.
0 commit comments