jsoneditor
jsoneditor copied to clipboard
Reevaluate "onEditable"
I want to use the "code" or "tree" modes for viewing JSON in readonly mode. However, I want to be able to switch the editor into read/write mode dynamically. At the moment "onEditable" is not reevaluated - can I force JSONEditor to reevaluate whether the JSON can be edited? The only method I've found is to switch mode and then back again - but this comes with its own problems (like cursor location changing, tree collapsing).
const options = {
mode: 'code',
modes: ['code', 'form', 'text', 'tree', 'view', 'preview'],
onEditable: function () {
return self.editJSON; <-- this can change dynamically.
}
};
this.jsoneditor = new JSONEditor(container, options);
Perhaps something like?:
this.jsoneditor.reevaluateOnEditable();
Thanks, -Neil
Good point, thanks for bringing this up Neil.
Maybe we can extend the existing method this.jsoneditor.refresh()
for that. This method is used for example to refresh class names in case you have a custom onClassName
configured. (Or does it already work for onEditable
too? I don't know by heart)
I did try refresh
but it didn't have the desired effect.
Thanks for testing that. Let's see if we can extend refresh
then to also trigger onEditable
.
Anyone able to implement this? Help would be welcome.
My work around is maintaining two instances of JSON editor, one editable and one read-only. Then write some code to decide which one to show based on my scenario. Not perfect but works. Hopefully we can get some update soon.