jsoneditor icon indicating copy to clipboard operation
jsoneditor copied to clipboard

Implement a way to trigger executing onEditable again

Open BerndSchrooten opened this issue 4 years ago • 2 comments

We have a case where we dynamically switch the editor from read-only to editable. However, in code or text mode this isn't applied properly because the onEditable callback is only called on creation.

https://github.com/josdejong/jsoneditor/blob/1e79ead1ec96a9acfdb8b35097595a3da5a9bacc/src/js/textmode.js#L255-L256

This is not clear from the docs:

In modes text and code, the callback is invoked as editable(node) where node is an empty object (no field, value, or path). In that case the function can return false to make the text or code editor completely read-only.

If it's not possible to handle this dynamically, having to call .refresh() to update the mode also comes a long way. Currently we recreate the editor when we want to switch from read-only to editable.

BerndSchrooten avatar Mar 05 '21 10:03 BerndSchrooten

Ah, that's an interesting case indeed.

I think we would need some method instead of a callback to accommodate for this, the callback does not have a reason to rerun itself out of nowhere. I think using .refresh() would make sense here: currently this forces to rerun onClassName everywhere, we could extend that to trigger onEditable everywhere too.

josdejong avatar Mar 06 '21 13:03 josdejong

Anyone interested in picking this up? Thinking this idea through a bit more and create a PR?

josdejong avatar Mar 06 '21 13:03 josdejong