Skip to content

Commit

Permalink
Update for bootstrap 3.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paltman committed Sep 1, 2013
1 parent ad7c426 commit 7c24033
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
64 changes: 34 additions & 30 deletions django_forms_bootstrap/templates/bootstrap/field.html
Expand Up @@ -3,47 +3,51 @@
{% if field.is_hidden %}
{{ field }}
{% else %}
<div id="div_{{ field.auto_id }}" class="control-group {% if field.errors %}error{% endif %} {% if field.css_classes %} {{ field.css_classes }}{% endif %}">
<div id="div_{{ field.auto_id }}" class="form-group {% if field.errors %}error{% endif %} {% if field.css_classes %} {{ field.css_classes }}{% endif %}">

{% if field.label and not field|css_class == "checkboxinput" %}
<label for="{{ field.auto_id }}" class="control-label {% if field.field.required %}required-field{% endif %}">
{{ field.label|safe }}
</label>
{% endif %}

<div class="controls">
{% if field|css_class == "checkboxselectmultiple" %}
{% include "bootstrap/_field_errors_block.html" %}
{% for choice in field.field.choices %}
<label class="checkbox">
<input type="checkbox" {% if choice.0 in field.value or choice.0 == field.value %}checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter }}" value="{{ choice.0 }}">{{ choice.1 }}
</label>
{% endfor %}
{% include "bootstrap/_field_help_text.html" %}
{% endif %}
{% if field|css_class == "radioselect" %}
{% include "bootstrap/_field_errors_block.html" %}
{% for choice in field.field.choices %}
<label class="radio">
<input type="radio" {% if choice.0 == field.value %}checked="checked" {% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter }}" value="{{ choice.0 }}">{{ choice.1 }}
{% if field|css_class == "checkboxselectmultiple" %}
{% include "bootstrap/_field_errors_block.html" %}
{% for choice in field.field.choices %}
<div class="checkbox">
<label>
<input type="checkbox" {% if choice.0 in field.value or choice.0 == field.value %}checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter }}" value="{{ choice.0 }}"> {{ choice.1 }}
</label>
{% endfor %}
{% include "bootstrap/_field_help_text.html" %}
{% endif %}
{% if field|css_class != "checkboxselectmultiple" and field|css_class != "radioselect" %}
{% if field|css_class == "checkboxinput" %}
<label for="{{ field.auto_id }}" class="checkbox {% if field.field.required %}required-field{% endif %}">
</div>
{% endfor %}
{% include "bootstrap/_field_help_text.html" %}
{% endif %}
{% if field|css_class == "radioselect" %}
{% include "bootstrap/_field_errors_block.html" %}
{% for choice in field.field.choices %}
<div class="radio">
<label>
<input type="radio" {% if choice.0 == field.value %}checked="checked" {% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter }}" value="{{ choice.0 }}"> {{ choice.1 }}
</label>
</div>
{% endfor %}
{% include "bootstrap/_field_help_text.html" %}
{% endif %}
{% if field|css_class != "checkboxselectmultiple" and field|css_class != "radioselect" %}
{% if field|css_class == "checkboxinput" %}
<div class="checkbox">
<label for="{{ field.auto_id }}" class="{% if field.field.required %}required-field{% endif %}">
{{ field }}
{{ field.label|safe }}
</label>
{% include "bootstrap/_field_errors_block.html" %}
{% include "bootstrap/_field_help_text.html" %}
{% else %}
{{ field }}
{% include "bootstrap/_field_errors.html" %}
{% include "bootstrap/_field_help_text.html" %}
{% endif %}
</div>
{% include "bootstrap/_field_errors_block.html" %}
{% include "bootstrap/_field_help_text.html" %}
{% else %}
{{ field }}
{% include "bootstrap/_field_errors.html" %}
{% include "bootstrap/_field_help_text.html" %}
{% endif %}
</div>
{% endif %}
</div>
{% endif %}
4 changes: 4 additions & 0 deletions django_forms_bootstrap/templatetags/bootstrap_tags.py
Expand Up @@ -9,6 +9,10 @@
@register.filter
def as_bootstrap(form):
template = get_template("bootstrap/form.html")
for field in form.fields:
name = form.fields[field].widget.__class__.__name__.lower()
if not name.startswith("radio") and not name.startswith("checkbox"):
form.fields[field].widget.attrs["class"] = " form-control"
c = Context({"form": form})
return template.render(c)

Expand Down

0 comments on commit 7c24033

Please sign in to comment.