Skip to content

Commit e3813dc

Browse files
author
a.volinsky
committed
Implement editor_options widget parameter
1 parent 70c8bf1 commit e3813dc

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

django_admin_json_editor/admin.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
class JSONEditorWidget(forms.Widget):
1111
template_name = 'django_admin_json_editor/editor.html'
1212

13-
def __init__(self, schema, collapsed=True, sceditor=False):
13+
def __init__(self, schema, collapsed=True, sceditor=False, editor_options=None):
1414
super(JSONEditorWidget, self).__init__()
1515
self._schema = schema
1616
self._collapsed = collapsed
1717
self._sceditor = sceditor
18+
self._editor_options = editor_options or {}
1819

1920
def render(self, name, value, attrs=None, renderer=None):
2021
if callable(self._schema):
@@ -25,11 +26,18 @@ def render(self, name, value, attrs=None, renderer=None):
2526
schema['title'] = ' '
2627
schema['options'] = {'collapsed': int(self._collapsed)}
2728

29+
editor_options = {
30+
'theme': 'bootstrap3',
31+
'iconlib': 'fontawesome4',
32+
'schema': schema,
33+
}
34+
editor_options.update(self._editor_options)
35+
2836
context = {
2937
'name': name,
30-
'schema': json.dumps(schema),
3138
'data': value,
3239
'sceditor': int(self._sceditor),
40+
'editor_options': json.dumps(editor_options),
3341
}
3442
return mark_safe(render_to_string(self.template_name, context))
3543

django_admin_json_editor/templates/django_admin_json_editor/editor.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
<script>
44
var container = document.getElementById("{{ name }}_editor");
5-
var options = {
6-
theme: "bootstrap3",
7-
iconlib: "fontawesome4",
8-
schema: {{ schema|safe }}
9-
};
5+
var options = {{ editor_options|safe }};
106
var {{ name }}_editor = new JSONEditor(container, options);
117
JSONEditor.plugins.sceditor.emoticonsEnabled = {{ sceditor }};
128
{{ name }}_editor.on('change', function () {

0 commit comments

Comments
 (0)