@@ -4,10 +4,10 @@ function init(Survey, $) {
44 activatedBy : "property" ,
55 name : "select2" ,
66 htmlTemplate : "<select style='width: 100%;'></select>" ,
7- widgetIsLoaded : function ( ) {
7+ widgetIsLoaded : function ( ) {
88 return typeof $ == "function" && ! ! $ . fn . select2 ;
99 } ,
10- isFit : function ( question ) {
10+ isFit : function ( question ) {
1111 if ( widget . activatedBy == "property" )
1212 return (
1313 question [ "renderAs" ] === "select2" &&
@@ -19,7 +19,7 @@ function init(Survey, $) {
1919 return question . getType ( ) === "select2" ;
2020 return false ;
2121 } ,
22- activatedByChanged : function ( activatedBy ) {
22+ activatedByChanged : function ( activatedBy ) {
2323 if ( ! this . widgetIsLoaded ( ) ) return ;
2424 widget . activatedBy = activatedBy ;
2525 Survey . JsonObject . metaData . removeProperty ( "dropdown" , "renderAs" ) ;
@@ -42,7 +42,7 @@ function init(Survey, $) {
4242 } ) ;
4343 }
4444 } ,
45- afterRender : function ( question , el ) {
45+ afterRender : function ( question , el ) {
4646 var settings = question . select2Config ;
4747 var $el = $ ( el ) . is ( "select" ) ? $ ( el ) : $ ( el ) . find ( "select" ) ;
4848 var othersEl = document . createElement ( "input" ) ;
@@ -55,24 +55,24 @@ function init(Survey, $) {
5555 . get ( 0 )
5656 . appendChild ( othersEl ) ;
5757
58- var updateValueHandler = function ( ) {
58+ var updateValueHandler = function ( ) {
5959 $el . val ( question . value ) . trigger ( "change" ) ;
6060 othersEl . style . display = ! question . isOtherSelected ? "none" : "" ;
6161 } ;
62- var updateCommentHandler = function ( ) {
62+ var updateCommentHandler = function ( ) {
6363 othersEl . value = question . comment ? question . comment : "" ;
6464 } ;
65- var othersElChanged = function ( ) {
65+ var othersElChanged = function ( ) {
6666 question . comment = othersEl . value ;
6767 } ;
68- var updateChoices = function ( ) {
68+ var updateChoices = function ( ) {
6969 $el . select2 ( ) . empty ( ) ;
7070
7171 if ( settings ) {
7272 if ( settings . ajax ) {
7373 $el . select2 ( settings ) ;
7474 } else {
75- settings . data = question . visibleChoices . map ( function ( choice ) {
75+ settings . data = question . visibleChoices . map ( function ( choice ) {
7676 return {
7777 id : choice . value ,
7878 text : choice . text
@@ -84,7 +84,7 @@ function init(Survey, $) {
8484 $el . select2 ( {
8585 theme : "classic" ,
8686 disabled : question . isReadOnly ,
87- data : question . visibleChoices . map ( function ( choice ) {
87+ data : question . visibleChoices . map ( function ( choice ) {
8888 return {
8989 id : choice . value ,
9090 text : choice . text
@@ -97,20 +97,16 @@ function init(Survey, $) {
9797 updateCommentHandler ( ) ;
9898 } ;
9999
100- var readOnlyUpdater = function ( sender , options ) {
101- if ( options . name === "isReadOnly" ) {
102- $el . prop ( "disabled" , question . isReadOnly ) ;
103- }
104- }
105- question . _readOnlyUpdater = readOnlyUpdater ;
106- question . onPropertyChanged . add ( readOnlyUpdater ) ;
100+ question . readOnlyChangedCallback = function ( ) {
101+ $el . prop ( "disabled" , question . isReadOnly ) ;
102+ } ;
107103
108104 question . choicesChangedCallback = updateChoices ;
109105 updateChoices ( ) ;
110- $el . on ( "select2:select" , function ( e ) {
106+ $el . on ( "select2:select" , function ( e ) {
111107 question . value = e . target . value ;
112108 } ) ;
113- $el . on ( "select2:unselecting" , function ( e ) {
109+ $el . on ( "select2:unselecting" , function ( e ) {
114110 question . value = null ;
115111 } ) ;
116112 othersEl . onchange = othersElChanged ;
@@ -119,15 +115,12 @@ function init(Survey, $) {
119115 updateValueHandler ( ) ;
120116 updateCommentHandler ( ) ;
121117 } ,
122- willUnmount : function ( question , el ) {
118+ willUnmount : function ( question , el ) {
123119 $ ( el )
124120 . find ( "select" )
125121 . off ( "select2:select" )
126122 . select2 ( "destroy" ) ;
127- if ( ! ! question . _readOnlyUpdater ) {
128- question . onPropertyChanged . remove ( question . _readOnlyUpdater ) ;
129- question . _readOnlyUpdater = undefined ;
130- }
123+ question . readOnlyChangedCallback = null ;
131124 }
132125 } ;
133126
@@ -138,4 +131,4 @@ if (typeof Survey !== "undefined") {
138131 init ( Survey , window . $ ) ;
139132}
140133
141- export default init ;
134+ export default init ;
0 commit comments