Merge branch 'eureka' of https://github.com/caumons/django-bootstrap-form into caumons-eureka

Conflicts:
	.gitignore
This commit is contained in:
tzangms 2013-12-06 03:31:07 +08:00
commit a15b054d0a
4 changed files with 27 additions and 13 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
docs/_build docs/_build
/build /build
/dist /dist
>>>>>>> aee2b719b27498f1b3dcbb1909a8443ff6d1cf9f

View File

@ -5,12 +5,12 @@
<div class="{{ classes.single_value }}"> <div class="{{ classes.single_value }}">
<div class="checkbox"> <div class="checkbox">
{% if field.auto_id %} {% if field.auto_id %}
<label> <label {% if field.field.required and form.required_css_class %}class="{{ form.required_css_class }}"{% endif %}>
{{ field }} <span>{{ field.label }}</span> {{ field }} <span>{{ field.label }}</span>
</label> </label>
{% endif %} {% endif %}
{% for error in field.errors %} {% for error in field.errors %}
<span class="help-block">{{ error }}</span> <span class="help-block {{ form.error_css_class }}">{{ error }}</span>
{% endfor %} {% endfor %}
{% if field.help_text %} {% if field.help_text %}
@ -20,9 +20,9 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% else %}{% if field|is_radio %} {% elif field|is_radio %}
{% if field.auto_id %} {% if field.auto_id %}
<label class="control-label {{ classes.label }}">{{ field.label }}</label> <label class="control-label {{ classes.label }} {% if field.field.required %}{{ form.required_css_class }}{% endif %}">{{ field.label }}</label>
{% endif %} {% endif %}
<div class="{{ classes.value }}"> <div class="{{ classes.value }}">
{% for choice in field %} {% for choice in field %}
@ -35,7 +35,7 @@
{% endfor %} {% endfor %}
{% for error in field.errors %} {% for error in field.errors %}
<span class="help-block">{{ error }}</span> <span class="help-block {{ form.error_css_class }}">{{ error }}</span>
{% endfor %} {% endfor %}
{% if field.help_text %} {% if field.help_text %}
@ -44,16 +44,16 @@
</p> </p>
{% endif %} {% endif %}
</div> </div>
{% else %} {% else %}
{% if field.auto_id %} {% if field.auto_id %}
<label class="control-label {{ classes.label }}" for="{{ field.auto_id }}">{{ field.label }}</label> <label class="control-label {{ classes.label }} {% if field.field.required %}{{ form.required_css_class }}{% endif %}" for="{{ field.auto_id }}">{{ field.label }}</label>
{% endif %} {% endif %}
<div class="{{ classes.value }}">
<div class="{{ classes.value }} {% if field|is_multiple_checkbox %}multiple-checkbox{% endif %}">
{{ field }} {{ field }}
{% for error in field.errors %} {% for error in field.errors %}
<span class="help-block">{{ error }}</span> <span class="help-block {{ form.error_css_class }}">{{ error }}</span>
{% endfor %} {% endfor %}
{% if field.help_text %} {% if field.help_text %}
@ -62,5 +62,5 @@
</p> </p>
{% endif %} {% endif %}
</div> </div>
{% endif %}{% endif %} {% endif %}
</div> </div>

View File

@ -48,7 +48,8 @@ def bootstrap_horizontal(element, label_cols={}):
def add_input_classes(field): def add_input_classes(field):
if not is_checkbox(field) and not is_multiple_checkbox(field) and not is_radio(field): if not is_checkbox(field) and not is_multiple_checkbox(field) and not is_radio(field) \
and not is_file(field):
field_classes = field.field.widget.attrs.get('class', '') field_classes = field.field.widget.attrs.get('class', '')
field_classes += ' form-control' field_classes += ' form-control'
field.field.widget.attrs['class'] = field_classes field.field.widget.attrs['class'] = field_classes
@ -93,3 +94,8 @@ def is_multiple_checkbox(field):
@register.filter @register.filter
def is_radio(field): def is_radio(field):
return field.field.widget.__class__.__name__.lower() == "radioselect" return field.field.widget.__class__.__name__.lower() == "radioselect"
@register.filter
def is_file(field):
return field.field.widget.__class__.__name__.lower() == "clearablefileinput"

View File

@ -6,6 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<title>Bootstrap form example</title> <title>Bootstrap form example</title>
<style type="text/css">
.multiple-checkbox ul { /* Used to hide <li> elements in multiple checkbox forms */
padding-left: 0px;
list-style: none;
}
</style>
</head> </head>
<body> <body>