@@ -145,22 +145,38 @@ function init(Survey, $) {
145145 ) ;
146146 updateChoices ( ) ;
147147 $el . on ( "select2:select" , function ( e ) {
148- question . renderedValue = e . target . value ;
149- updateComment ( ) ;
148+ setTimeout ( function ( ) {
149+ question . renderedValue = e . target . value ;
150+ updateComment ( ) ;
151+ } , 1 ) ;
152+ } ) ;
153+ $el . on ( 'select2:opening' , function ( e ) {
154+ if ( $ ( this ) . data ( 'unselecting' ) ) {
155+ $ ( this ) . removeData ( 'unselecting' ) ;
156+ e . preventDefault ( ) ;
157+ }
150158 } ) ;
151159 $el . on ( "select2:unselecting" , function ( e ) {
152- question . renderedValue = null ;
153- updateComment ( ) ;
160+ $ ( this ) . data ( 'unselecting' , true ) ;
161+ setTimeout ( function ( ) {
162+ question . renderedValue = null ;
163+ updateComment ( ) ;
164+ } , 1 ) ;
154165 } ) ;
155166 question . valueChangedCallback = updateValueHandler ;
156167 updateValueHandler ( ) ;
157168 } ,
158169 willUnmount : function ( question , el ) {
170+ question . readOnlyChangedCallback = null ;
171+ question . valueChangedCallback = null ;
159172 var $select2 = $ ( el ) . find ( "select" ) ;
160173 if ( ! ! $select2 . data ( "select2" ) ) {
161- $select2 . off ( "select2:select" ) . select2 ( "destroy" ) ;
174+ $select2
175+ . off ( "select2:select" )
176+ . off ( "select2:unselecting" )
177+ . off ( "select2:opening" )
178+ . select2 ( "destroy" ) ;
162179 }
163- question . readOnlyChangedCallback = null ;
164180 } ,
165181 } ;
166182
0 commit comments