plantain-00 / schema-based-json-editor

A reactjs and vuejs component of schema based json editor.
MIT License
169 stars 38 forks source link

when schema changes, fields are not updated #12

Open shagabay opened 6 years ago

shagabay commented 6 years ago

hi,

thanks for your support !

not sure if this is a bug in the editor itself or in the component, but when i change some field name, the changes are not reflected in the editor:

you can replicate with the attached example, click on 'onClick1' and then 'onClick2'. the field 'firstName' is renamed in the schema by the code (see app.vue) to 'firstName2', but you can see that it's not reflected in the editor.

a workaround is also good at this point...

thanks sharon example.zip

plantain-00 commented 6 years ago

It is kind of buggy when the schema is changed after initialization finished. I found it is difficult to fix it. My use case is when a field is like true, field firstName exists, when field is false, fleld firstName2 exists and firstName disappear, I can use the non-standard requiredWhen (https://github.com/plantain-00/schema-based-json-editor#features ; the online demo shows it too) to do this.

shagabay commented 6 years ago

another solution i've found:

<json-editor v-if="visible" // USING V-IF TO TOGGLE VISIBILITY OF THE EDITOR, HENCE CREATE/DESTROY :schema="schema" :initial-value="value" theme="bootstrap4" icon="fontawesome4">

...

data () {
  return {
    visible: true,

...

  onClick: function (event) {
    this.schema = JSON.parse(this.editorText)
    this.visible = false
    setTimeout(() => this.visible = true, 50);
    // TOGGLING VISIBILITY WITHOUT A TIMEOUT DIDN'T WORK
  }