Frage

I have to create a multipage form and was wondering if I can just follow Pylons documentation on helper functions to build forms in CKAN?

Is there any documentation in CKAN for creating forms? Please suggest the best approach.

War es hilfreich?

Lösung

CKAN forms usually import some macros located in ckan/templates/macros. Have a look at form.html and you'll get the idea. Also have a look at one of the examples (ckanext/example_idatasetform).

Basically you'd import the macros with {% import 'macros/form.html' as form %} and then build the form with those macros, like this:

{% block package_basic_fields_custom %}
{{ form.input('custom_text', label=_('Custom Text'), 
id='field-custom_text', placeholder=_('custom text'), 
value=data.custom_text, error=errors.custom_text, classes= ['control-medium']) }}
{% endblock %}   

AFAIK there's no special documention on how to create forms in CKAN. You should have a look at the relevant templates in ckan/templates/package

Andere Tipps

Yes, there is documentation for the built-in form element macros for CKAN 2.6.0a in the comments of /usr/lib/ckan/default/src/ckan/ckan/templates/macros/form.html, and also in the Frontend Development Guidelines, under Templating.

Note that the documentation tells you to add the line:

{% import 'macros/form.html' as form %}

but if you're overriding an existing template (using {% ckan_extends %}) you don't typically have to add this import line because that is usually already in place, or already included in a parent template.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top