Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load static %}

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

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

Expand Down
5 changes: 4 additions & 1 deletion django_svelte_jsoneditor/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
class SvelteJSONEditorWidget(Textarea):
template_name = "django_svelte_jsoneditor/widgets/svelte_jsoneditor.html"

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

self.props = {} if props is None else props.copy()
self.wrapper_class = wrapper_class

check_props(self.props)
attrs.update({"class": "hidden"})

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

class Media:
Expand Down
Loading
Loading