Skip to content
Snippets Groups Projects
Commit 44ffb521 authored by Dennis Ahrens's avatar Dennis Ahrens
Browse files

Change class rendering.

Instead of relying on an attribute that is not always there,
check for the passed widget and decide which class to add.
parent 423f7fb0
No related branches found
No related tags found
1 merge request!2Change class rendering.
from django import template from django import template
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.forms.widgets import TextInput, Textarea
from hshassets.forms.utils import render_form_field, render_form_generics, render_form_errors from hshassets.forms.utils import render_form_field, render_form_generics, render_form_errors
from hshassets.forms.elements import Field from hshassets.forms.elements import Field
...@@ -16,8 +17,10 @@ def bulma_form_fields(form): ...@@ -16,8 +17,10 @@ def bulma_form_fields(form):
widget_classes = list() 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 isinstance(field.field.widget, TextInput):
widget_classes.append("input") widget_classes.append("input")
elif isinstance(field.field.widget, Textarea):
widget_classes.append("textarea")
# highlight fields with errors # highlight fields with errors
if field.errors: if field.errors:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment