dmstr / yii2-json-editor

Yii2 wrapper for "json-editor/json-editor" (is a fork of "jdorn/json-editor").
BSD 2-Clause "Simplified" License
8 stars 9 forks source link

JSONEditor startval instead of setValue after Initialization #10

Closed germanbisurgi closed 5 years ago

germanbisurgi commented 5 years ago

I would like to propose to use the "startval" option during the initialization of the JSON Editor instead of setting the value after the instance creation.

Current: new JSONEditor -> ready (no data yet) -> setValue () Proposition: new JSONEditor(startval) -> ready (data already loaded)

This is useful for editors that implements plugins like selectize.js because they need an input that already has a value. Listening to the ready event insures that.

schmunk42 commented 5 years ago

@germanbisurgi Is this just a thing of this widget or would it require also changes in json-editor?

CC: @pmk65 this is just FYI

germanbisurgi commented 5 years ago

it will affect only the yii2-json-editor/src/JsonEditorWidget.php file

schmunk42 commented 5 years ago

@dmstr/developers If there's feedback from your side, raise your voice.

Otherwise @germanbisurgi ... go ahead ;)

pmk65 commented 5 years ago

Isn't that feature already available or am I missing something? In my Playground page, I initialize the editor like this, (setting the "startval" parameter if I got data):

var opt = 'schema:' + schema + (startval.trim() ? ', startval:' + startval : '');
return 'var jseditor = new window.JSONEditor(document.querySelector("#json-editor-form"),{' + opt + '});';
germanbisurgi commented 5 years ago

The startval feature already exists in the json-editor/json-editor. But is not being leveraged in the dmstr/yii2-json-editor/src/JsonEditorWidget.php script.

pmk65 commented 5 years ago

@germanbisurgi My mistake. I totally overlooked that this was a different repo. 😁