Skip to content

Commit 16499e9

Browse files
authored
fix attrs in outer context (#8)
1 parent 036088f commit 16499e9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/django_formify/tailwind/formify_helper.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,12 @@ def render_form(self, context):
186186
"""
187187
uni_form.html
188188
"""
189-
return SafeString(
190-
self.render_form_errors(context) + self.render_form_fields(context)
191-
)
189+
with context.push():
190+
context["attrs"] = None
191+
192+
return SafeString(
193+
self.render_form_errors(context) + self.render_form_fields(context)
194+
)
192195

193196
def render_field(self, context, field, **kwargs):
194197
"""
@@ -201,6 +204,7 @@ def render_field(self, context, field, **kwargs):
201204
setattr(field_formify_helper, key, value)
202205

203206
with context.push():
207+
context["attrs"] = None
204208
context["field"] = field
205209

206210
if field.is_hidden:
@@ -268,7 +272,7 @@ def render_as_tailwind_field(self, context):
268272
field = context["field"]
269273
widget = field.field.widget
270274

271-
attrs = context.get("attrs", {})
275+
attrs = context.get("attrs", None) or {}
272276
css_class = widget.attrs.get("class", "")
273277
if "class" not in attrs.keys():
274278
# if class is not set, then add additional css classes
@@ -296,7 +300,7 @@ def render_as_tailwind_field(self, context):
296300
# TODO
297301
for attribute_name, attributes in attrs.items():
298302
if attribute_name in widget.attrs:
299-
# multiple attribtes are in a single string, e.g.
303+
# multiple attributes are in a single string, e.g.
300304
# "form-control is-invalid"
301305
for attr in attributes.split():
302306
if attr not in widget.attrs[attribute_name].split():

0 commit comments

Comments
 (0)