Closed Franciman closed 5 years ago
@pmk65 do you have any tip for this?
@Franciman Im not quite sure what you mean by loosing Preview Editor.
@pmk65 for example, suppose you have the Person schema, you put some data in the Preview Editor(e.g. Name: 'Jon', Age: 25, etc..) then you realize you don't need The name field anymore, so you update the schema. Now when you update the Preview Editor, all the data you previously inserted are lost
Ok. Now I get it. 😄
1) Turn on "No additional object properties" for the Preview Editor. (This will prevent creation of field when you set a value for a non-existing field)
2) Before updating Preview Editor, save the content. ( previewEditor.getValue()
)
3) Update the Preview Editor from the Schema Editor and use the values saved in step 2 as starting value (startval
).
What if a field changed type? E.g. from string to int. I get a validation error. I tried solving that issue by running
var errors = editor.validate(oldValue);
And then for each error reported I remove the field in the oldValue that gives that error (chasing it thanks to error.path
)
Do you know of a better approach?
It will just validate the value as invalid (I think the int/number types automatically converts any non digit value to zero)
Your approach seems a good way to do it.
thank you for the support!
Yes, thanks again @pmk65 for your support.
Hey, did you see that the schema editor is now being used in the wild? https://github.com/DeepBlueCLtd/json-schema-editor/issues/24
It's in a TiddlyWiki clone, and I've loved TiddlyWiki for over 10 years. Very exciting :-)
Hey, did you see that the schema editor is now being used in the wild?
24
Yeah. I saw that. Very nice 😃
When one only adds or removes a field from the schema, it would be wasteful to totally lose the Preview Editor, instead it would be preferable to keep the old values, when possible.