Created
May 22, 2017 22:06
-
-
Save doobeh/742501f51a393352b95cbd67de3b8c0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% macro bsfield(field) -%} | |
| {% set with_label = kwargs.pop('with_label', False) %} | |
| {% set placeholder = '' %} | |
| {% if not with_label %} | |
| {% set placeholder = field.label.text %} | |
| {% endif %} | |
| <div class="form-group {% if field.errors %}error{% endif %}"> | |
| {% if with_label %} | |
| <label for="{{ field.id }}"> | |
| {{ field.label.text }}{% if field.flags.required %} *{% endif %}: | |
| </label> | |
| {% endif %} | |
| {% set class_ = kwargs.pop('class_', '') %} | |
| {% if field.flags.required %} | |
| {% set class_ = class_ + ' required' %} | |
| {% endif %} | |
| {% if field.type == 'BooleanField' %} | |
| <label class="checkbox"> | |
| {{ field(class_=class_, **kwargs) }} | |
| {{ field.label.text|safe }} | |
| </label> | |
| {% else %} | |
| {% if field.type in ('TextField', 'TextAreaField', 'PasswordField') %} | |
| {% set class_ = class_ + ' input-xlarge' %} | |
| {% elif field.type == 'FileField' %} | |
| {% set class_ = class_ + ' input-file' %} | |
| {% endif %} | |
| {{ field(class_=class_, placeholder=placeholder, **kwargs) }} | |
| {% endif %} | |
| {% if field.errors %} | |
| <span class="error help-inline">{{ field.errors|join(', ') }}</span> | |
| {% endif %} | |
| {% if field.description %} | |
| <p class="help-block">{{ field.description|safe }}</p> | |
| {% endif %} | |
| </div> | |
| {%- endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment