Skip to content

Commit f0b8488

Browse files
committed
Remove attr if dynamic attr value is None
1 parent 40869d4 commit f0b8488

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

widget_tweaks/templatetags/widget_tweaks.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,13 @@ def render(self, context):
225225
else:
226226
attr_dict[k] = v.resolve(context)
227227
for k, v in attr_dict.items():
228-
if k == "type":
229-
bounded_field.field.widget.input_type = v
228+
if v:
229+
if k == "type":
230+
bounded_field.field.widget.input_type = v
231+
else:
232+
bounded_field = set_attr(bounded_field, f"{k}:{v}")
230233
else:
231-
bounded_field = set_attr(bounded_field, f"{k}:{v}")
234+
bounded_field = remove_attr(bounded_field, k)
232235
for k, v in self.append_attrs:
233236
bounded_field = append_attr(bounded_field, f"{k}:{v.resolve(context)}")
234237
return str(bounded_field)

0 commit comments

Comments
 (0)