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 13
13
use yii \helpers \ArrayHelper ;
14
14
use yii \helpers \Html ;
15
15
use yii \helpers \Json ;
16
+ use yii \web \View ;
16
17
use yii \widgets \InputWidget as BaseWidget ;
17
18
18
19
/**
@@ -78,6 +79,13 @@ class JsonEditorWidget extends BaseWidget
78
79
*/
79
80
private $ _renderInput = true ;
80
81
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
+
81
89
/**
82
90
* Initializes the widget
83
91
* @inheritdoc
@@ -175,11 +183,15 @@ public function run()
175
183
176
184
$ readyFunction = '' ;
177
185
$ 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
+ }
179
190
$ widgetJs .= "{$ widgetId }.on('ready', function() { \n{$ readyFunction }\n}); " ;
180
191
181
192
// Register js code
182
193
$ view ->registerJs ($ widgetJs , $ view ::POS_READY );
194
+
183
195
$ this ->registerAdditionalLanguages ();
184
196
185
197
parent ::run ();
You can’t perform that action at this time.
0 commit comments