Skip to content

Commit

Permalink
fix attrs in outer context (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-yin authored Jan 13, 2025
1 parent 036088f commit 16499e9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/django_formify/tailwind/formify_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ def render_form(self, context):
"""
uni_form.html
"""
return SafeString(
self.render_form_errors(context) + self.render_form_fields(context)
)
with context.push():
context["attrs"] = None

return SafeString(
self.render_form_errors(context) + self.render_form_fields(context)
)

def render_field(self, context, field, **kwargs):
"""
Expand All @@ -201,6 +204,7 @@ def render_field(self, context, field, **kwargs):
setattr(field_formify_helper, key, value)

with context.push():
context["attrs"] = None
context["field"] = field

if field.is_hidden:
Expand Down Expand Up @@ -268,7 +272,7 @@ def render_as_tailwind_field(self, context):
field = context["field"]
widget = field.field.widget

attrs = context.get("attrs", {})
attrs = context.get("attrs", None) or {}
css_class = widget.attrs.get("class", "")
if "class" not in attrs.keys():
# if class is not set, then add additional css classes
Expand Down Expand Up @@ -296,7 +300,7 @@ def render_as_tailwind_field(self, context):
# TODO
for attribute_name, attributes in attrs.items():
if attribute_name in widget.attrs:
# multiple attribtes are in a single string, e.g.
# multiple attributes are in a single string, e.g.
# "form-control is-invalid"
for attr in attributes.split():
if attr not in widget.attrs[attribute_name].split():
Expand Down

0 comments on commit 16499e9

Please sign in to comment.