Commit 052aef12 authored by Malcolm's avatar Malcolm

Add documentation for _form.html and _form_field.html and amend checkout display

parent b1ed20be
Pipeline #13291004 passed with stage
in 57 seconds
{% comment %}
Template to display a form using styling from the form and pure-css.
Parameters that can be passed (in the with clause of an include) are:
action: Url to send the submitted form to e.g.'/search/' default is '.'
i.e. the current url
aligned: Boolean variable, if true the 'pure-form-aligned' class is applied
if false the class 'pure-form-stacked' is appled
form_class: Additional css classes to apply to the form tag
form_id: Id attribute for the form e.g. id_search_form
inline_checkbox: Boolean variable, if true checkboxes are displayed inline
regardless of whether the form is stacked or aligned, styling
is determined by aligned variable
legend: Legend to display at the top of the form
method: The submit method, e.g. GET, POST
submit: Legend for the submit button (default is 'Submit')
submit_id: Id of the submit button
submit_2_id and submit_2_name and submit_2_value: three variables to allow
definition of a second submit button and define it's id, name and
value.
{% endcomment %}
<style>
.pure-form-stacked input[type=checkbox] ~ strong label { display: inline-block !important; }
</style>
<form action="{% if action %}{{ action }}{% else %}.{% endif %}" {% if form_id %}id="{{ form_id }}"{% endif %} method="{% if method %}{{ method }}{% else %}post{% endif %}" {% if multipart %}enctype="multipart/form-data"{% endif %} class="pure-form {% if aligned %}pure-form-aligned{% else %}pure-form-stacked{% endif %}{% if form_class %} {{ form_class }}{% endif %}">
{% if not no_token %}
{% csrf_token %}
......@@ -10,7 +45,11 @@
<legend>{{ legend }}</legend>
{% endif %}
{% for field in form.visible_fields %}
{% include '_form_field.html' with field=field %}
{% if inline_checkbox and field.field.widget.input_type %}
{% include '_form_field.html' with field=field field_type=field.field.widget.input_type %}
{% else %}
{% include '_form_field.html' with field=field %}
{% endif %}
{% endfor %}
{% if formset %}
{{ formset.management_form }}
......@@ -25,7 +64,11 @@
{% endif %}
</legend>
{% for field in formset_form.visible_fields %}
{% include '_form_field.html' with field=field %}
{% if inline_checkbox %}
{% include '_form_field.html' with field=field field_type=field.field.widget.input_type %}
{% else %}
{% include '_form_field.html' with field=field %}
{% endif %}
{% endfor %}
{% for hidden in formset_form.hidden_fields %}
{{ hidden }}
......@@ -33,7 +76,7 @@
{% endfor %}
<div class="pure-controls">
<p>
<input type="submit" {% if submit_id %}id="{{ submit_id }}"{% else %}id="submit"{% endif %} value="{% if submit %}{{ submit }}{% else %}Submit{% endif %}" class="pure-button pure-button-primary" />
<input type="submit" id="{% if submit_id %}{{ submit_id }}{% else %}submit{% endif %}" value="{% if submit %}{{ submit }}{% else %}Submit{% endif %}" class="pure-button pure-button-primary" />
{% if submit_2_id and submit_2_name and submit_2_value %}
<input type="submit" id="{{ submit_2_id }}" name="{{ submit_2_name }}" value="{{ submit_2_value }}" class="pure-button" />
{% endif %}
......
{% comment %}
Template ito display a form field using styling from the form and pure-css.
Designed to be called from _form.html
Parameters that can be passed (in the with clause of an include) are:
aligned: Boolean variable aligned displays field on the same line after the
label if not fields are displayed on the next line
input_type: Currently only used to change the layout of a checkbox. when the
value is checkbox the field is displayed before the label and the
aligned parameter is ignored. Potentially other values could be
used to control the behavior of other field types.
{% endcomment %}
<div class="pure-control-group">
{% if field_type == 'checkbox' %}
{{ field }}
{% endif %}
{% if field.label %}
<strong>
<label for='{{ field.id_for_label }}'>{{ field.label }}{% if field.help_text %} - {{ field.help_text }}{% endif %}:</label>
<label for='{{ field.id_for_label }}'>{{ field.label }}{% if field.help_text %} - {{ field.help_text }}{% endif %}{% if field_type != 'checkbox' %}:{% endif %}</label>
</strong>
{% endif %}
{% if aligned %}
{% if aligned and not field_type == 'checkbox' %}
{{ field }}
{% endif %}
{% for error in field.errors %}
<span class="errorlist"><mark>{{ error }}</mark></span>
{% if not aligned %}
{% if not aligned and not field_type == 'checkbox' %}
<br>
{% endif %}
{% endfor %}
{% if not aligned %}
{% if not aligned and not field_type == 'checkbox' %}
{{ field }}
{% endif %}
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment