File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 1313use yii \helpers \ArrayHelper ;
1414use yii \helpers \Html ;
1515use yii \helpers \Json ;
16+ use yii \web \View ;
1617use yii \widgets \InputWidget as BaseWidget ;
1718
1819/**
@@ -78,6 +79,13 @@ class JsonEditorWidget extends BaseWidget
7879 */
7980 private $ _renderInput = true ;
8081
82+ /**
83+ * Disable the editor and set it in a readonly state
84+ * @var bool
85+ * @link https://github.com/json-editor/json-editor#enable-and-disable-the-editor
86+ */
87+ public $ disabled = false ;
88+
8189 /**
8290 * Initializes the widget
8391 * @inheritdoc
@@ -175,11 +183,15 @@ public function run()
175183
176184 $ readyFunction = '' ;
177185 $ readyFunction .= "{$ widgetId }.on('change', function() { document.getElementById(' {$ inputId }').value = JSON.stringify( {$ widgetId }.getValue()); }); \n" ;
178-
186+ if ($ this ->disabled ) {
187+ // Disabled last added json editor
188+ $ readyFunction .= 'window.jsonEditors.slice(-1)[0].disable() ' ;
189+ }
179190 $ widgetJs .= "{$ widgetId }.on('ready', function() { \n{$ readyFunction }\n}); " ;
180191
181192 // Register js code
182193 $ view ->registerJs ($ widgetJs , $ view ::POS_READY );
194+
183195 $ this ->registerAdditionalLanguages ();
184196
185197 parent ::run ();
You can’t perform that action at this time.
0 commit comments