@@ -77,7 +77,7 @@ class SmartSelect extends Framework7Class {
77
77
const value = ss . $selectEl . val ( ) ;
78
78
ss . $el . trigger ( 'smartselect:change' , ss , value ) ;
79
79
ss . emit ( 'local::change smartSelectChange' , ss , value ) ;
80
- ss . setValue ( ) ;
80
+ ss . setTextValue ( ) ;
81
81
}
82
82
ss . attachEvents = function attachEvents ( ) {
83
83
$el . on ( 'click' , onClick ) ;
@@ -141,6 +141,43 @@ class SmartSelect extends Framework7Class {
141
141
return ss ;
142
142
}
143
143
144
+ setValue ( value ) {
145
+ const ss = this ;
146
+ let newValue = value ;
147
+ let optionText = [ ] ;
148
+ let optionEl ;
149
+ let displayAs ;
150
+ let text ;
151
+ if ( ss . multiple ) {
152
+ if ( ! Array . isArray ( newValue ) ) newValue = [ newValue ] ;
153
+ for ( let i = 0 ; i < ss . selectEl . options . length ; i += 1 ) {
154
+ optionEl = ss . selectEl . options [ i ] ;
155
+ if ( newValue . indexOf ( optionEl . value ) >= 0 ) {
156
+ optionEl . selected = true ;
157
+ } else {
158
+ optionEl . selected = false ;
159
+ }
160
+ if ( optionEl . selected ) {
161
+ displayAs = optionEl . dataset ? optionEl . dataset . displayAs : $ ( optionEl ) . data ( 'display-value-as' ) ;
162
+ text = displayAs && typeof displayAs !== 'undefined' ? displayAs : optionEl . textContent ;
163
+ optionText . push ( text . trim ( ) ) ;
164
+ }
165
+ }
166
+ } else {
167
+ optionEl = ss . $selectEl . find ( `option[value="${ newValue } "]` ) [ 0 ] ;
168
+ displayAs = optionEl . dataset ? optionEl . dataset . displayAs : $ ( optionEl ) . data ( 'display-as' ) ;
169
+ text = displayAs && typeof displayAs !== 'undefined' ? displayAs : optionEl . textContent ;
170
+ optionText = [ text ] ;
171
+ ss . selectEl . value = newValue ;
172
+ }
173
+ ss . $valueEl . text ( optionText . join ( ', ' ) ) ;
174
+ }
175
+
176
+ getValue ( ) {
177
+ const ss = this ;
178
+ return ss . $selectEl . val ( ) ;
179
+ }
180
+
144
181
getView ( ) {
145
182
const ss = this ;
146
183
let view = ss . view || ss . params . view ;
@@ -170,7 +207,7 @@ class SmartSelect extends Framework7Class {
170
207
}
171
208
}
172
209
173
- setValue ( value ) {
210
+ setTextValue ( value ) {
174
211
const ss = this ;
175
212
let valueArray = [ ] ;
176
213
if ( typeof value !== 'undefined' ) {
@@ -712,7 +749,7 @@ class SmartSelect extends Framework7Class {
712
749
init ( ) {
713
750
const ss = this ;
714
751
ss . attachEvents ( ) ;
715
- ss . setValue ( ) ;
752
+ ss . setTextValue ( ) ;
716
753
}
717
754
718
755
destroy ( ) {
0 commit comments