django-jsoneditor
django-jsoneditor copied to clipboard
Read-only mode?
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?
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.
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})}}
I've opened a PR to allow per-field customization of both initialization and ace options. #66