From 2beb4aa7d7087a4235f3310e01928f5e797e2717 Mon Sep 17 00:00:00 2001 From: vocaviking Date: Mon, 21 Dec 2015 00:27:15 +0100 Subject: [PATCH 1/2] Added EmailField which has a given domain ending I added a new Field, which uses the aria functionality described in http://getbootstrap.com/components/#input-groups-basic This enables to set a fixed domain ending for Email Input. (But only optically. In the form_valid the domain has to be checked again!) --- This is the first of two edit. Next thing I do, will be updating the template. --- bootstrapform/templatetags/bootstrap.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/bootstrapform/templatetags/bootstrap.py b/bootstrapform/templatetags/bootstrap.py index a8b96de..f4f8923 100644 --- a/bootstrapform/templatetags/bootstrap.py +++ b/bootstrapform/templatetags/bootstrap.py @@ -9,20 +9,26 @@ @register.filter def bootstrap(element): - markup_classes = {'label': '', 'value': '', 'single_value': ''} + markup_classes = {'label': '', 'value': '', 'single_value': '', 'domain': ''} return render(element, markup_classes) +@register.filter +def bootstrap_email(element, domain='example.com'): + markup_classes = {'label': '', 'value': '', 'single_value': '', 'domain': domain} + element.field.widget.attrs.update({'aria-describedby' : element.id_for_label + '-addon'}) + element.field.widget.attrs.update({'class' : 'form-control' }) + return render(element, markup_classes) @register.filter def bootstrap_inline(element): - markup_classes = {'label': 'sr-only', 'value': '', 'single_value': ''} + markup_classes = {'label': 'sr-only', 'value': '', 'single_value': '', 'domain': ''} return render(element, markup_classes) @register.filter def bootstrap_horizontal(element, label_cols='col-sm-2 col-lg-2'): - markup_classes = {'label': label_cols, 'value': '', 'single_value': ''} + markup_classes = {'label': label_cols, 'value': '', 'single_value': '', 'domain': ''} for cl in label_cols.split(' '): splitted_class = cl.split('-') @@ -48,7 +54,8 @@ def bootstrap_horizontal(element, label_cols='col-sm-2 col-lg-2'): @register.filter def add_input_classes(field): if not is_checkbox(field) and not is_multiple_checkbox(field) \ - and not is_radio(field) and not is_file(field): + and not is_radio(field) and not is_file(field) \ + and not is_email(field): field_classes = field.field.widget.attrs.get('class', '') field_classes += ' form-control' field.field.widget.attrs['class'] = field_classes @@ -79,6 +86,10 @@ def render(element, markup_classes): return template.render(context) +@register.filter +def is_email(field): + return isinstance(field.field.widget, forms.EmailInput) + @register.filter def is_checkbox(field): From 0bc3b2db5128fe624a6cdf5f25ce8dbb5935bbad Mon Sep 17 00:00:00 2001 From: vocaviking Date: Mon, 21 Dec 2015 00:35:35 +0100 Subject: [PATCH 2/2] Added EmailField which has a given domain ending I added a new Field, which uses the aria functionality described in http://getbootstrap.com/components/#input-groups-basic This enables to set a fixed domain ending for Email Input. (But only optically. In the form_valid the domain has to be checked again!) --- This is the second of two edit. We are now complete! --- .../templates/bootstrapform/field.html | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bootstrapform/templates/bootstrapform/field.html b/bootstrapform/templates/bootstrapform/field.html index bfbdf64..ea7d607 100644 --- a/bootstrapform/templates/bootstrapform/field.html +++ b/bootstrapform/templates/bootstrapform/field.html @@ -44,6 +44,27 @@

{% endif %} + {% elif field|is_email and classes.domain %} + {% if field.auto_id %} + + {% endif %} + +
+
+ {{ field }} + {{ classes.domain }} +
+ + {% for error in field.errors %} + {{ error }} + {% endfor %} + + {% if field.help_text %} +

+ {{ field.help_text|safe }} +

+ {% endif %} +
{% else %} {% if field.auto_id %}