Skip to content

Commit 391d932

Browse files
authored
Merge pull request #31 from grahamhoyes/widget-wrapper-class
ENH: Allow setting the container class
2 parents d1118fe + ce5b938 commit 391d932

File tree

4 files changed

+585
-529
lines changed

4 files changed

+585
-529
lines changed

django_svelte_jsoneditor/templates/django_svelte_jsoneditor/widgets/svelte_jsoneditor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% load static %}
22

3-
<div id="jsoneditor_{{ widget.attrs.id }}" class="svelte-jsoneditor-wrapper"></div>
3+
<div id="jsoneditor_{{ widget.attrs.id }}" class="{{ widget.wrapper_class }}"></div>
44

55
<textarea name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>{% if widget.value %}{{ widget.value }}{% endif %}</textarea>
66

django_svelte_jsoneditor/widgets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
class SvelteJSONEditorWidget(Textarea):
88
template_name = "django_svelte_jsoneditor/widgets/svelte_jsoneditor.html"
99

10-
def __init__(self, props=None, attrs=None):
10+
def __init__(self, props=None, attrs=None, wrapper_class="svelte-jsoneditor-wrapper"):
1111
if attrs is None:
1212
attrs = {}
1313

1414
self.props = {} if props is None else props.copy()
15+
self.wrapper_class = wrapper_class
16+
1517
check_props(self.props)
1618
attrs.update({"class": "hidden"})
1719

@@ -20,6 +22,7 @@ def __init__(self, props=None, attrs=None):
2022
def get_context(self, name, value, attrs):
2123
context = super().get_context(name, value, attrs)
2224
context["widget"].update({"props": json.dumps({**get_props(), **self.props})})
25+
context["widget"].update({"wrapper_class": self.wrapper_class})
2326
return context
2427

2528
class Media:

0 commit comments

Comments
 (0)