Skip to content

Commit

Permalink
[#2302] add autoform to form macros
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 3, 2012
1 parent 0ffe609 commit 7775262
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ckan/templates/macros/form.html
Expand Up @@ -296,3 +296,38 @@
{{ " " }}{{ key }}{% if value != "" %}="{{ value }}"{% endif %}
{%- endfor -%}
{%- endmacro -%}

{%- macro autoform(form_info=[], data={}, errors={}) -%}
{% for item in form_info %}
{% set name = item.name %}
{% set value = data.get(name) %}
{% set error = errors.get(name) %}
{% set id = 'field-%s' % name %}

{% set control = item.control or 'input' %}
{% set label = item.label %}
{% set placeholder = item.placeholder %}

{% set classes = item.classes %}

{% if control == 'input' %}

{{ input(name, id=id, label=label, placeholder=placeholder, value=value, error=error, classes=classes or ['control-medium']) }}

{% elif control == 'select' %}

{% set options = item.options %}
{{ select(name, id=id, label=label, options=options, selected=value, error=error) }}

{% elif control == 'markdown' %}

{{ markdown(name, id=id, label=label, placeholder=placeholder, value=value, error=error) }}

{% elif control == 'plain_textarea' %}

{{ plain_textarea(name, id=id, label=label, placeholder=placeholder, value=value, error=error) }}

{% endif %}

{% endfor %}
{%- endmacro -%}

0 comments on commit 7775262

Please sign in to comment.