@@ -1736,14 +1736,18 @@ the specific language governing permissions and limitations under the Apache Lic
17361736
17371737 // single
17381738 val : function ( ) {
1739- var val , data = null , self = this ;
1739+ var val , triggerChange = true , data = null , self = this ;
17401740
17411741 if ( arguments . length === 0 ) {
17421742 return this . opts . element . val ( ) ;
17431743 }
17441744
17451745 val = arguments [ 0 ] ;
17461746
1747+ if ( arguments . length > 1 ) {
1748+ triggerChange = arguments [ 1 ] ;
1749+ }
1750+
17471751 if ( this . select ) {
17481752 this . select
17491753 . val ( val )
@@ -1753,15 +1757,19 @@ the specific language governing permissions and limitations under the Apache Lic
17531757 } ) ;
17541758 this . updateSelection ( data ) ;
17551759 this . setPlaceholder ( ) ;
1756- this . triggerChange ( ) ;
1760+ if ( triggerChange ) {
1761+ this . triggerChange ( ) ;
1762+ }
17571763 } else {
17581764 if ( this . opts . initSelection === undefined ) {
17591765 throw new Error ( "cannot call val() if initSelection() is not defined" ) ;
17601766 }
17611767 // val is an id. !val is true for [undefined,null,'']
17621768 if ( ! val ) {
17631769 this . clear ( ) ;
1764- this . triggerChange ( ) ;
1770+ if ( triggerChange ) {
1771+ this . triggerChange ( ) ;
1772+ }
17651773 return ;
17661774 }
17671775 this . opts . element . val ( val ) ;
@@ -2278,19 +2286,25 @@ the specific language governing permissions and limitations under the Apache Lic
22782286
22792287 // multi
22802288 val : function ( ) {
2281- var val , data = [ ] , self = this ;
2289+ var val , triggerChange = true , data = [ ] , self = this ;
22822290
22832291 if ( arguments . length === 0 ) {
22842292 return this . getVal ( ) ;
22852293 }
22862294
22872295 val = arguments [ 0 ] ;
22882296
2297+ if ( arguments . length > 1 ) {
2298+ triggerChange = arguments [ 1 ] ;
2299+ }
2300+
22892301 if ( ! val ) {
22902302 this . opts . element . val ( "" ) ;
22912303 this . updateSelection ( [ ] ) ;
22922304 this . clearSearch ( ) ;
2293- this . triggerChange ( ) ;
2305+ if ( triggerChange ) {
2306+ this . triggerChange ( ) ;
2307+ }
22942308 return ;
22952309 }
22962310
@@ -2302,7 +2316,9 @@ the specific language governing permissions and limitations under the Apache Lic
23022316 data . push ( { id : $ ( this ) . attr ( "value" ) , text : $ ( this ) . text ( ) } ) ;
23032317 } ) ;
23042318 this . updateSelection ( data ) ;
2305- this . triggerChange ( ) ;
2319+ if ( triggerChange ) {
2320+ this . triggerChange ( ) ;
2321+ }
23062322 } else {
23072323 if ( this . opts . initSelection === undefined ) {
23082324 throw new Error ( "val() cannot be called if initSelection() is not defined" )
@@ -2313,7 +2329,9 @@ the specific language governing permissions and limitations under the Apache Lic
23132329 self . setVal ( ids ) ;
23142330 self . updateSelection ( data ) ;
23152331 self . clearSearch ( ) ;
2316- self . triggerChange ( ) ;
2332+ if ( triggerChange ) {
2333+ self . triggerChange ( ) ;
2334+ }
23172335 } ) ;
23182336 }
23192337 this . clearSearch ( ) ;
0 commit comments