Skip to content

Commit

Permalink
Remove attr if dynamic attr value is None
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbelyayev committed Jan 8, 2025
1 parent 40869d4 commit a5801b9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions widget_tweaks/templatetags/widget_tweaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ def render(self, context):
else:
attr_dict[k] = v.resolve(context)
for k, v in attr_dict.items():
if k == "type":
bounded_field.field.widget.input_type = v
if v is None:
bounded_field = remove_attr(bounded_field, k)
else:
bounded_field = set_attr(bounded_field, f"{k}:{v}")
if k == "type":
bounded_field.field.widget.input_type = v
else:
bounded_field = set_attr(bounded_field, f"{k}:{v}")
for k, v in self.append_attrs:
bounded_field = append_attr(bounded_field, f"{k}:{v.resolve(context)}")
return str(bounded_field)
Expand Down

0 comments on commit a5801b9

Please sign in to comment.