Skip to content
Snippets Groups Projects
Commit a8e3bc54 authored by Art's avatar Art :lizard:
Browse files

Tag bulmaform now updates widget attrs instead of resetting them.

parent 256e6f86
Branches
No related tags found
No related merge requests found
...@@ -11,13 +11,17 @@ register = template.Library() ...@@ -11,13 +11,17 @@ register = template.Library()
def bulmaform(form): def bulmaform(form):
"""Templatetag to render forms with bulma styles and elements""" """Templatetag to render forms with bulma styles and elements"""
# because the <input> tag will be rendered by django's internals, it is easier to give the widgets # append bulma css classes to widgets and let django render these widgets
# a css-class rather than render every <input> tag by mysqlf
for field in form: for field in form:
widget_classes = list()
# not every form element in bulma has the 'input' css class, so we need to differ here # not every form element in bulma has the 'input' css class, so we need to differ here
if getattr(field.field.widget, 'input_type', None) not in ['checkbox', 'radio']: if getattr(field.field.widget, 'input_type', None) not in ['checkbox', 'radio']:
field.field.widget.attrs = {'class': 'input' + (' is-danger' if field.errors else '')} widget_classes.append("input")
# highlight fields with errors
if field.errors:
widget_classes.append("is-danger")
# done
field.field.widget.attrs["class"] = " ".join(widget_classes)
if getattr(form, 'layout', None): if getattr(form, 'layout', None):
output = render_layout(form.layout, form) output = render_layout(form.layout, form)
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment