@@ -49,6 +49,9 @@ function init(Survey, $) {
4949 var self = this ;
5050 var settings = question . select2Config ;
5151 var $el = $ ( el ) . is ( "select" ) ? $ ( el ) : $ ( el ) . find ( "select" ) ;
52+
53+ self . willUnmount ( question , el ) ;
54+
5255 $el . select2 ( {
5356 tags : "true" ,
5457 disabled : question . isReadOnly ,
@@ -90,14 +93,16 @@ function init(Survey, $) {
9093 updateValueHandler ( ) ;
9194 } ;
9295
96+ question . _propertyValueChangedFnSelect2 = function ( ) {
97+ updateChoices ( ) ;
98+ } ;
99+
93100 question . readOnlyChangedCallback = function ( ) {
94101 $el . prop ( "disabled" , question . isReadOnly ) ;
95102 } ;
96103 question . registerFunctionOnPropertyValueChanged (
97104 "visibleChoices" ,
98- function ( ) {
99- updateChoices ( ) ;
100- }
105+ question . _propertyValueChangedFnSelect2
101106 ) ;
102107 question . valueChangedCallback = updateValueHandler ;
103108 $el . on ( "select2:select" , function ( e ) {
@@ -114,11 +119,19 @@ function init(Survey, $) {
114119 updateChoices ( ) ;
115120 } ,
116121 willUnmount : function ( question , el ) {
122+ if ( ! question . _propertyValueChangedFnSelect2 ) return ;
123+
117124 $ ( el )
118125 . find ( "select" )
119126 . off ( "select2:select" )
120127 . select2 ( "destroy" ) ;
121128 question . readOnlyChangedCallback = null ;
129+ question . valueChangedCallback = null ;
130+ question . unRegisterFunctionOnPropertyValueChanged (
131+ "visibleChoices" ,
132+ question . _propertyValueChangedFnSelect2
133+ ) ;
134+ question . _propertyValueChangedFnSelect2 = undefined ;
122135 }
123136 } ;
124137
0 commit comments