added ability to output individual fields
This commit is contained in:
parent
f7c5a705b2
commit
0499097467
@ -32,3 +32,5 @@ Usage
|
||||
{% load bootstrap %}
|
||||
|
||||
{{ form|bootstrap }}
|
||||
|
||||
{{ form.<field name>|bootstrap }} - To output individual fields
|
37
bootstrapform/templates/bootstrapform/field.html
Normal file
37
bootstrapform/templates/bootstrapform/field.html
Normal file
@ -0,0 +1,37 @@
|
||||
{% load bootstrap %}
|
||||
<div class="control-group{% if field.errors %} error{% endif %}">
|
||||
{% if field|is_checkbox %}
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
{{ field }} <span>{{ field.label }}</span>
|
||||
</label>
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help-inline">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help-block">
|
||||
{{ field.help_text }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="control-label">{{ field.label }}</div>
|
||||
|
||||
<div class="controls">
|
||||
{{ field }}
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help-inline">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help-block">
|
||||
{{ field.help_text }}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
@ -1,5 +1,3 @@
|
||||
{% load bootstrap %}
|
||||
|
||||
{{ form.non_field_errors }}
|
||||
|
||||
{% for field in form.hidden_fields %}
|
||||
@ -7,41 +5,6 @@
|
||||
{% endfor %}
|
||||
|
||||
{% for field in form.visible_fields %}
|
||||
<div class="control-group{% if field.errors %} error{% endif %}">
|
||||
{% if field|is_checkbox %}
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
{{ field }} <span>{{ field.label }}</span>
|
||||
</label>
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help-inline">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help-block">
|
||||
{{ field.help_text }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="control-label">{{ field.label }}</div>
|
||||
|
||||
<div class="controls">
|
||||
{{ field }}
|
||||
|
||||
{% for error in field.errors %}
|
||||
<span class="help-inline">{{ error }}</span>
|
||||
{% endfor %}
|
||||
|
||||
{% if field.help_text %}
|
||||
<p class="help-block">
|
||||
{{ field.help_text }}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% include 'bootstrapform/field.html' %}
|
||||
{% endfor %}
|
||||
|
||||
|
@ -5,9 +5,15 @@ from django import template
|
||||
register = template.Library()
|
||||
|
||||
@register.filter
|
||||
def bootstrap(form):
|
||||
template = get_template("bootstrapform/form.html")
|
||||
context = Context({'form': form})
|
||||
def bootstrap(element):
|
||||
element_type = element.__class__.__name__.lower()
|
||||
if element_type == 'boundfield':
|
||||
template = get_template("bootstrapform/field.html")
|
||||
context = Context({'field': element})
|
||||
else:
|
||||
template = get_template("bootstrapform/form.html")
|
||||
context = Context({'form': element})
|
||||
|
||||
return template.render(context)
|
||||
|
||||
@register.filter
|
||||
|
Loading…
Reference in New Issue
Block a user