{% macro form_field(field, field_name, parent_id) %} {%- set ns=namespace(minlength=False, maxlength=False, pattern=False) %} {%- set required=field.is_required() %} {%- if field.metadata %} {%- for meta in field.metadata %} {%- if meta.min_length %}{% set ns.minlength=meta.min_length %}{% endif %} {%- if meta.max_length %}{% set ns.maxlength=meta.max_length %}{% endif %} {%- if meta.pattern %}{% set ns.pattern=meta.pattern %}{% endif %} {%- endfor %} {%- endif %} {%- set closing_tag=False %} {%- set input_type=None %} {% if field.annotation.__args__ %} {% set annotation = field.annotation.__args__[0] %} {% else %} {% set annotation = field.annotation %} {% endif %} {% set autocomplete=field.json_schema_extra.autocomplete %} {%- if field.json_schema_extra and field.json_schema_extra.get('input_type', None) == 'textarea' %} {%- set element="textarea" %} {%- set closing_tag=True %} {%- set cls="form-textarea form-input" %} {%- elif annotation.__members__ %} {%- set element="select" %} {%- set closing_tag=True %} {%- set cls="form-select form-input" %} {%- elif annotation.__name__ == "bool" %} {%- set element="input" %} {%- set input_type="checkbox" %} {%- set checked=field.default is true %} {%- set cls="form-checkbox form-input" %} {%- elif annotation.__name__ == "datetime" %} {%- set element="input" %} {%- set input_type="datetime-local" %} {%- set cls="form-datetime form-input" %} {%- else %} {%- set element="input" %} {%- set cls="form-input" %} {%- endif -%}
{{ ns.pattern }}
{% endif %}
{% if required %}required{% endif %}
Option | Description |
---|---|
{{ key }} | {{ val.__metadata__[-1] }} |
{{ field.description }}
{% endif %}