Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Allow setting the container class #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.