Created
October 13, 2011 16:02
-
-
Save gnunicorn/1284631 to your computer and use it in GitHub Desktop.
Jinja2 WTForms macros for twitter bootstrap
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 form_field_label(field) -%} | |
<label for="{{ field.id }}">{{ field.label.text }} | |
{%- if field.flags.required -%} | |
<abbr title="Diese Feld muss angegeben werden">*</abbr> | |
{%- endif %}</label> | |
{% endmacro %} | |
{%- macro form_field_description(field) -%} | |
{% if field.description %} | |
<span class="descr">{{ field.description }}</span> | |
{% endif %} | |
{%- endmacro -%} | |
{%- macro form_field_errors(field) -%} | |
{% if field.errors %} | |
<div> | |
{%- for error in field.errors -%} | |
<span class="label important">{{ error }}</span> | |
{%- endfor -%} | |
</div> | |
{% endif %} | |
{%- endmacro -%} | |
{%- macro form_field_boolean(field) -%} | |
<div class="input"> | |
<label> | |
{{ field(**kwargs) }} | |
<span>{{ field.label.text }}</span> | |
{{ form_field_description(field) }} | |
{{ form_field_errors(field) }} | |
</label> | |
</div> | |
{%- endmacro -%} | |
{%- macro action_buttons(submit_title, cancel_title="Zurück setzten", submit_class="primary") -%} | |
<div class="actions"> | |
<input type="submit" class="btn {{submit_class}}" value="{{submit_title}}"> | |
| |
<button type="reset" class="btn">{{cancel_title}}</button> | |
</div> | |
{%- endmacro -%} | |
{%- macro form_field(field) -%} | |
<div class="clearfix"> | |
{% if field.type == 'HiddenField' %} | |
{{ field() }} | |
{% else %} | |
{% if field.type == 'BooleanField' %} | |
{{ form_field_boolean(field, **kwargs) }} | |
{% else%} | |
{{ form_field_label(field) }} | |
<div class="input" id="{{field.id}}-div"> | |
{% if field.type == 'RadioField' %} | |
{{ field(class='radio-group', **kwargs) }} | |
{% else %} | |
{{ field(**kwargs) }} | |
{% endif %} | |
{{ form_field_description(field) }} | |
{{ form_field_errors(field) }} | |
</div> | |
{% endif %} | |
{% endif %} | |
</div> | |
{%- endmacro -%} | |
{%- macro form_fields(fields, class=None, legend=None) -%} | |
<fieldset {% if class %}class="{{class}}"{% endif %}> | |
{% if legend %} | |
<legend>{{legend}}</legend> | |
{% endif %} | |
{% for field in fields %} | |
{% if field.type == 'HiddenField' %} | |
{{ field() }} | |
{% else %} | |
{{ form_field(field) }} | |
{% endif %} | |
{% endfor %} | |
</fieldset> | |
{%- endmacro -%} |
Awesome.
nice macros, it saved me on creating bootstrap forms.
Really Awesome One! Thank you!
Thanks a lot - also saved me some time!
Thanks! saved me time, but what about "autofocus" ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some simple jinja2 macros to import for doing WTForms for twitter bootstrap http://twitter.github.com/bootstrap/#forms projects. Have fun using them :)