Skip to content

Commit

Permalink
fix attrs in outer context
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-yin committed Jan 13, 2025
1 parent 036088f commit 497b13f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/django_formify/tailwind/formify_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import re
import warnings

from django.template.base import Template
from django.template.context import Context
Expand Down Expand Up @@ -268,7 +269,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 All @@ -295,8 +296,16 @@ def render_as_tailwind_field(self, context):

# TODO
for attribute_name, attributes in attrs.items():
# check type of attributes, if it is not basic type boolen, number, string, ignore it
# and print warning
if not isinstance(attributes, (bool, int, str)):
warnings.warn(
f"Attribute {attribute_name} value is not a basic type. Ignoring it.",
stacklevel=1,
)
continue
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 497b13f

Please sign in to comment.