Skip to content

Instantly share code, notes, and snippets.

@danielmt
Last active December 21, 2015 04:29
Show Gist options
  • Save danielmt/6250312 to your computer and use it in GitHub Desktop.
Save danielmt/6250312 to your computer and use it in GitHub Desktop.
Extends crispy-forms templates support for bootstrap3 adding classes for field and label. (INCOMPLETE)
diff --git a/crispy_forms/templates/bootstrap3/field.html b/crispy_forms/templates/bootstrap3/field.html
index 466160d..a7cfd45 100644
--- a/crispy_forms/templates/bootstrap3/field.html
+++ b/crispy_forms/templates/bootstrap3/field.html
@@ -5,7 +5,7 @@
{% else %}
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="form-group{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if form_show_errors%}{% if field.errors %} has-error{% endif %}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label and not field|is_checkbox and form_show_labels %}
- <label for="{{ field.id_for_label }}" class="control-label {% if field.field.required %}requiredField{% endif %}">
+ <label for="{{ field.id_for_label }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
@@ -19,7 +19,7 @@
{% endif %}
{% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
- <div class="controls">
+ <div class="controls {{ field_class }}">
{% if field|is_checkbox and form_show_labels %}
<label for="{{ field.id_for_label }}" class="checkbox {% if field.field.required %}requiredField{% endif %}">
{% crispy_field field %}
diff --git a/crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple.html b/crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple.html
index 35f4db4..d57dfff 100644
--- a/crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple.html
+++ b/crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple.html
@@ -1,4 +1,4 @@
-<div class="controls"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>
+<div class="controls {{ field_class }}"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>
{% include 'bootstrap3/layout/field_errors_block.html' %}
{% for choice in field.field.choices %}
diff --git a/crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple_inline.html b/crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple_inline.html
index 3bcd988..394480d 100644
--- a/crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple_inline.html
+++ b/crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple_inline.html
@@ -4,7 +4,7 @@
<div id="div_{{ field.auto_id }}" class="form-group{% if form_show_errors and field.errors %} has-error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label %}
- <label for="{{ field.auto_id }}" class="control-label{% if field.field.required %} requiredField{% endif %}">
+ <label for="{{ field.auto_id }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
diff --git a/crispy_forms/templates/bootstrap3/layout/radioselect.html b/crispy_forms/templates/bootstrap3/layout/radioselect.html
index 3c9d89e..a4a6311 100644
--- a/crispy_forms/templates/bootstrap3/layout/radioselect.html
+++ b/crispy_forms/templates/bootstrap3/layout/radioselect.html
@@ -1,4 +1,4 @@
-<div class="controls"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>
+<div class="controls {{ field_class }}"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>
{% include 'bootstrap3/layout/field_errors_block.html' %}
{% for choice in field.field.choices %}
diff --git a/crispy_forms/templates/bootstrap3/layout/radioselect_inline.html b/crispy_forms/templates/bootstrap3/layout/radioselect_inline.html
index 37070e7..65351b0 100644
--- a/crispy_forms/templates/bootstrap3/layout/radioselect_inline.html
+++ b/crispy_forms/templates/bootstrap3/layout/radioselect_inline.html
@@ -4,7 +4,7 @@
<div id="div_{{ field.auto_id }}" class="form-group{% if form_show_errors and field.errors %} has-error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label %}
- <label for="{{ field.auto_id }}" class="control-label{% if field.field.required %} requiredField{% endif %}">
+ <label for="{{ field.auto_id }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment