{#
Creates all the markup required for an input element. Handles matching labels to
inputs, error messages and other useful elements.
name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
value - The value of the input.
placeholder - Some placeholder text.
type - The type of input eg. email, url, date (default: text).
error - A list of error strings for the field or just true to highlight the field.
classes - An array of classes to apply to the control-group.
is_required - Boolean of whether this input is requred for the form to validate
Examples:
{% import 'macros/form.html' as form %}
{{ form.input('title', label=_('Title'), value=data.title, error=errors.title) }}
#}
{% macro input(name, id='', label='', value='', placeholder='', type='text', error="", classes=[], attrs={},
is_required=false) %}
{%- set extra_html = caller() if caller -%}
{%- set _type = 'text' if type=='date' and not value else type -%}
{%- set onFocus = 'onfocus=(this.type=\'date\')' if type=='date' and not value else '' -%}
{% call input_block(id or name, label, error, classes, extra_html=extra_html, is_required=is_required) %}
{% if error is iterable and error is not string %}
{{error|first}}
{% elif error is string %}
{{error}}
{% endif %}
{% endcall %}
{% endmacro %}
{% macro input_raw(name, id='', label='', value='', placeholder='', type='text', error="", classes=[], attrs={},
is_required=false) %}
{%- set extra_html = caller() if caller -%}
{%- set _type = 'text' if type=='date' and not value else type -%}
{%- set onFocus = 'onfocus=(this.type=\'date\')' if type=='date' and not value else '' -%}
{% call input_block(id or name, label, error, classes, extra_html=extra_html, is_required=is_required) %}
{% endcall %}
{% endmacro %}
{% macro input_extra(field, value='', index='', placeholder='', type='text', attrs={}) %}
{%- set _type = 'text' if type=='date' and not value else type -%}
{%- set onFocus = 'onfocus=(this.type=\'date\')' if type=='date' and not value else '' -%}
{% endmacro %}
{#
Builds a single checkbox input.
name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
value - The value of the input.
checked - If true the checkbox will be checked
error - An error string for the field or just true to highlight the field.
classes - An array of classes to apply to the control-group.
is_required - Boolean of whether this input is requred for the form to validate
Example:
{% import 'macros/form.html' as form %}
{{ form.checkbox('remember', checked=true) }}
#}
{% macro checkbox(name, id='', label='', value='', checked=false, placeholder='', error="", classes=[], attrs={},
is_required=false) %}
{%- set extra_html = caller() if caller -%}
{{ extra_html }}
{% endmacro %}
{% macro select(name, id='', label='', options='', selected='', error='', classes=[], attrs={'class': 'form-control'}, is_required=false) %}
{% set classes = (classes|list) %}
{% do classes.append('control-select') %}
{%- set extra_html = caller() if caller -%}
{% call input_block(id or name, label or name, error, classes, extra_html=extra_html, is_required=is_required) %}
{% endcall %}
{% endmacro %}
{#
Creates all the markup required for an select element. Handles matching labels to
inputs and error messages.
A field should be a dict with a "value" key and an optional "text" key which
will be displayed to the user. We use a dict to easily allow extension in
future should extra options be required.
name - The name of the form parameter.
id - The id to use on the input and label. Convention is to prefix with 'field-'.
label - The human readable label.
options - A list/tuple of fields to be used as .
selected - The value of the selected