Skip to content

Commit

Permalink
updated json editor schema widget
Browse files Browse the repository at this point in the history
eluhr committed Sep 7, 2020

Verified

This commit was signed with the committer’s verified signature.
1 parent 75d1093 commit a9754e2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/JsonEditorSchemaWidget.php
Original file line number Diff line number Diff line change
@@ -65,10 +65,11 @@ public function run()
private function registerAssets()
{
$ajaxUrl = Url::to($this->ajaxUrl);
$jsonEditorContainerId = Html::getInputId($this->model, $this->jsonEditorAttribute) . '-container';
$jsonEditorInputId = Html::getInputId($this->model, $this->jsonEditorAttribute);
$jsonEditorContainerId = $jsonEditorInputId . '-container';
$select2Id = Html::getInputId($this->model, $this->attribute);
$jsonEditorOptions = json_encode($this->jsonEditorOptions);

$this->view->registerJs(<<<JS
$("#{$select2Id}").on("select2:select", function () {
var value = $(this).val();
@@ -89,6 +90,10 @@ private function registerAssets()
jsonEditors[index].destroy();
jsonEditors[index] = new JSONEditor(document.getElementById("{$jsonEditorContainerId}"), jsonEditorOptions)
jsonEditors[index].on("change", function () {
document.getElementById("{$jsonEditorInputId}").value = JSON.stringify(this.getValue());
})
}
})
});

0 comments on commit a9754e2

Please sign in to comment.