@@ -1757,14 +1757,18 @@ the specific language governing permissions and limitations under the Apache Lic
17571757
17581758 // single
17591759 val : function ( ) {
1760- var val , data = null , self = this ;
1760+ var val , triggerChange = true , data = null , self = this ;
17611761
17621762 if ( arguments . length === 0 ) {
17631763 return this . opts . element . val ( ) ;
17641764 }
17651765
17661766 val = arguments [ 0 ] ;
17671767
1768+ if ( arguments . length > 1 ) {
1769+ triggerChange = arguments [ 1 ] ;
1770+ }
1771+
17681772 if ( this . select ) {
17691773 this . select
17701774 . val ( val )
@@ -1774,15 +1778,19 @@ the specific language governing permissions and limitations under the Apache Lic
17741778 } ) ;
17751779 this . updateSelection ( data ) ;
17761780 this . setPlaceholder ( ) ;
1777- this . triggerChange ( ) ;
1781+ if ( triggerChange ) {
1782+ this . triggerChange ( ) ;
1783+ }
17781784 } else {
17791785 if ( this . opts . initSelection === undefined ) {
17801786 throw new Error ( "cannot call val() if initSelection() is not defined" ) ;
17811787 }
17821788 // val is an id. !val is true for [undefined,null,'']
17831789 if ( ! val ) {
17841790 this . clear ( ) ;
1785- this . triggerChange ( ) ;
1791+ if ( triggerChange ) {
1792+ this . triggerChange ( ) ;
1793+ }
17861794 return ;
17871795 }
17881796 this . opts . element . val ( val ) ;
@@ -2302,19 +2310,25 @@ the specific language governing permissions and limitations under the Apache Lic
23022310
23032311 // multi
23042312 val : function ( ) {
2305- var val , data = [ ] , self = this ;
2313+ var val , triggerChange = true , data = [ ] , self = this ;
23062314
23072315 if ( arguments . length === 0 ) {
23082316 return this . getVal ( ) ;
23092317 }
23102318
23112319 val = arguments [ 0 ] ;
23122320
2321+ if ( arguments . length > 1 ) {
2322+ triggerChange = arguments [ 1 ] ;
2323+ }
2324+
23132325 if ( ! val ) {
23142326 this . opts . element . val ( "" ) ;
23152327 this . updateSelection ( [ ] ) ;
23162328 this . clearSearch ( ) ;
2317- this . triggerChange ( ) ;
2329+ if ( triggerChange ) {
2330+ this . triggerChange ( ) ;
2331+ }
23182332 return ;
23192333 }
23202334
@@ -2326,7 +2340,9 @@ the specific language governing permissions and limitations under the Apache Lic
23262340 data . push ( { id : $ ( this ) . attr ( "value" ) , text : $ ( this ) . text ( ) } ) ;
23272341 } ) ;
23282342 this . updateSelection ( data ) ;
2329- this . triggerChange ( ) ;
2343+ if ( triggerChange ) {
2344+ this . triggerChange ( ) ;
2345+ }
23302346 } else {
23312347 if ( this . opts . initSelection === undefined ) {
23322348 throw new Error ( "val() cannot be called if initSelection() is not defined" )
@@ -2337,7 +2353,9 @@ the specific language governing permissions and limitations under the Apache Lic
23372353 self . setVal ( ids ) ;
23382354 self . updateSelection ( data ) ;
23392355 self . clearSearch ( ) ;
2340- self . triggerChange ( ) ;
2356+ if ( triggerChange ) {
2357+ self . triggerChange ( ) ;
2358+ }
23412359 } ) ;
23422360 }
23432361 this . clearSearch ( ) ;
0 commit comments