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 af07e24
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions widget_tweaks/templatetags/widget_tweaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,15 @@ 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:
if isinstance(v, bool):
bounded_field = set_attr(bounded_field, f"{k}")
if k == "type":
bounded_field.field.widget.input_type = v
else:
bounded_field = set_attr(bounded_field, f"{k}:{v}")
else:
bounded_field = set_attr(bounded_field, f"{k}:{v}")
bounded_field = remove_attr(bounded_field, k)
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 af07e24

Please sign in to comment.