jdorn / json-editor

JSON Schema Based Editor
MIT License
5.81k stars 1.08k forks source link

Select api & update json based on schema of item returned #802

Closed tkuben closed 6 years ago

tkuben commented 6 years ago

Hi All,

I would like to have an enumSource reference an API which pulls the list of items. Each item in the list contains a schema of its own. Upon change, I would like to append to the select box, the schema that they have chosen to allow the user to enter values for it. I have updated my jsoneditor code with the following pull request: https://github.com/jdorn/json-editor/pull/720 and made my own changes. Now, on the onChange portion of the select, I have the following:

onInputChange: function() {
  var val = this.input.value;

  var editor = this.jsoneditor.getEditorClass(this.enumSource[0].source[val].schema);

  var ret = this.jsoneditor.createEditor(editor,{
    jsoneditor: this.jsoneditor,
    schema: this.enumSource[0].source[val].schema,
    container: this.container,
    path: this.path,
    parent: this
  });
  ret.preBuild();
  ret.build();
  ret.postBuild();

This successfully pulls the schema of the item and appends to the select box, however it is not updating the global json editor with the new schema I've added. It only contains the select box but not the item I have chosen. How can I register this such that the item's schema I have selected is also included into the global schema?

Thank you Cheers, TJ

tkuben commented 6 years ago

I've implemented this feature in my own fork of the project for those that are interested: https://github.com/tkuben/json-editor/commits/master