File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,18 @@ public function run()
137137 // Prepare client options
138138 $ clientOptions = $ this ->clientOptions ;
139139 $ clientOptions ['schema ' ] = $ this ->schema ;
140- ArrayHelper::remove ($ clientOptions , 'startval ' );
140+
141+ try {
142+ $ parsedValue = Json::decode ($ this ->value );
143+ } catch (\Exception $ e ) {
144+ $ parsedValue = null ;
145+ \Yii::error ($ e ->getMessage (), __METHOD__ );
146+ }
147+
148+ if (!empty ($ parsedValue )) {
149+ $ clientOptions ['startval ' ] = $ parsedValue ;
150+ }
151+
141152 $ clientOptions = Json::encode ($ clientOptions );
142153
143154 // Prepare element IDs
@@ -151,17 +162,6 @@ public function run()
151162 $ widgetJs .= "if (!window.jsonEditors) { window.jsonEditors = []; } window.jsonEditors.push(window. {$ widgetId }); " ;
152163
153164 $ readyFunction = '' ;
154- try {
155- $ parsedValue = Json::decode ($ this ->value );
156- } catch (\Exception $ e ) {
157- $ parsedValue = null ;
158- }
159-
160- if (!empty ($ parsedValue )) {
161- $ encodedValue = Json::encode ($ parsedValue );
162- $ readyFunction .= "try { {$ widgetId }.setValue( {$ encodedValue }); } catch (e) { console.warn('Could not parse initial value for {$ widgetId }, error: '+e); } \n" ;
163- }
164-
165165 $ readyFunction .= "{$ widgetId }.on('change', function() { document.getElementById(' {$ inputId }').value = JSON.stringify( {$ widgetId }.getValue()); }); \n" ;
166166
167167 $ widgetJs .= "{$ widgetId }.on('ready', function() { \n{$ readyFunction }\n}); " ;
You can’t perform that action at this time.
0 commit comments