Browse Source

Small trick: we add a filter to the Django templating in order to add some class to our form inputs

pull/250/head
Guillim 5 years ago
parent
commit
9caf7751fa
2 changed files with 11 additions and 0 deletions
  1. 1
      app/app/settings.py
  2. 10
      app/authentification/templatetags/utils_templating.py

1
app/app/settings.py

@ -97,6 +97,7 @@ TEMPLATES = [
],
'libraries': {
'analytics': 'server.templatetags.analytics',
'utils_templating': 'authentification.templatetags.utils_templating',
},
},
},

10
app/authentification/templatetags/utils_templating.py

@ -0,0 +1,10 @@
from django import template
register = template.Library()
@register.filter(name='addcss')
def addcss(value, arg):
css_classes = value.field.widget.attrs.get('class', '').split(' ')
if css_classes and arg not in css_classes:
css_classes = '%s %s' % (css_classes, arg)
return value.as_widget(attrs={'class': css_classes})
Loading…
Cancel
Save