{# Reusable form field macros for CRUD forms. Adapted for Bootstrap 3. #} {# Internal helper for help text #} {% macro _help(text) %}{% if text %}{{ text }}{% endif %}{% endmacro %} {% macro text_input(name, label, value='', help='', readonly=false, required=false, type='text', maxlength=none) %}
{{ _help(help) }}
{% endmacro %} {% macro date_input(name, label, value='', help='', required=false, min='') %}
{{ _help(help) }}
{% endmacro %} {% macro number_input(name, label, value='', help='', min=none, max=none, step=none) %}
{{ _help(help) }}
{% endmacro %} {% macro textarea(name, label, value='', help='', rows=3) %}
{{ _help(help) }}
{% endmacro %} {% macro select(name, label, options, selected='', help='', readonly=false, placeholder='') %}
{# When disabled, add hidden input to submit the value (disabled fields don't submit) #} {% if readonly %}{% endif %} {{ _help(help) }}
{% endmacro %} {% macro checkbox(name, label, id, checked=false, value='true') %}
{% endmacro %} {% macro checkbox_list(name, label, options, selected=[], help='', scrollable=false) %}
{% if help %}

{{ help }}

{% endif %} {% for opt in options %} {# Support both plain values and (value, label) tuples #} {% if opt is iterable and opt is not string and opt | length == 2 %}
{% else %}
{% endif %} {% endfor %}
{% endmacro %} {% macro readonly_field(label, value, help='') %}
{{ _help(help) }}
{% endmacro %} {% macro hidden_input(name, value) %} {% endmacro %}