django-jsoneditor icon indicating copy to clipboard operation
django-jsoneditor copied to clipboard

Read-only mode?

Open shacker opened this issue 2 years ago • 3 comments

With django-json-widget, we were able to make some of our JSONFields read-only like this:

    formfield_overrides = {
        JSONField: {"widget": JSONEditorWidget(options={"mode": "view", "modes": ["view"]})}
    }

We are trying to switch to django-jsoneditor, but this no longer seems possible. If I initialize with:

formfield_overrides = {JSONField: {"widget": JSONEditor(options={"mode": "view", "modes": ["view"]})}}

Django crashes on options. If I remove that:

formfield_overrides = {JSONField: {"widget": JSONEditor({"mode": "view", "modes": ["view"]})}}

Django doesn't crash, but the field is still editable. I read the docs on overriding the JS init, but that applies to the whole Django Project, while I just want to do this for a few selected JSONFields.

What's the right way to customize the options for a single editor instance?

shacker avatar Jun 03 '22 21:06 shacker

Hi!

Unfortunately, there is no ready-to-use solution for your problem.

If you have a good solution, feel free to suggest a PR for your needs.

I will leave this issue open to implementation later.

nnseva avatar Jun 29 '22 14:06 nnseva

Here's a workaround. It doesn't restrict the modes, but it does keep it read only.

formfield_overrides = {JSONField: {"widget": JSONEditor(attrs={'disabled': True})}}

GregKaleka avatar Aug 27 '22 14:08 GregKaleka

I've opened a PR to allow per-field customization of both initialization and ace options. #66

GregKaleka avatar Aug 27 '22 17:08 GregKaleka