Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

More forms enhancements #117

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions src/_includes/macros/form.njk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
>
{% if data.description %}
<br>
<em class="[ field-list__field-group__description ]" id="description-{{ name }}">{{ data.description }}</em>
{{ description( name, data.description ) }}
{% endif %}
{% endmacro %}

Expand All @@ -41,7 +41,7 @@
</label>
{% if data.description %}
<br>
<em class="[ field-list__field-group__description ]" id="description-{{ name }}">{{ data.description }}</em>
{{ description( name, data.description ) }}
{% endif %}
{% endmacro %}

Expand All @@ -53,19 +53,27 @@
{% if data.multiple %}multiple{% endif %}
{% if data.description %}aria-describedby="description-{{ name }}"{% endif %}
>
{% for option in data.options_before %}
<option>{{ option }}</option>
{% for opt in data.options_before %}
{{ option( opt ) }}
{% endfor %}
{% for option in options %}
<option>{{ option }}</option>
{% for opt in options %}
{{ option( opt ) }}
{% endfor %}
{% for option in data.options_after %}
<option>{{ option }}</option>
{% for opt in data.options_after %}
{{ option( opt ) }}
{% endfor %}
</select>
{% if data.description %}
<br>
<em class="[ field-list__field-group__description ]" id="description-{{ name }}">{{ data.description }}</em>
{{ description( name, data.description ) }}
{% endif %}
{% endmacro %}

{% macro option( data ) %}
{% if data.value %}
<option value="{{ data.value }}">{{ data.label }}</option>
{% else %}
<option>{{ data }}</option>
{% endif %}
{% endmacro %}

Expand All @@ -82,7 +90,7 @@
{% if data.description %}aria-describedby="description-{{ name }}"{% endif %}
></textarea>
{% if data.description %}
<em class="[ field-list__field-group__description ]" id="description-{{ name }}">{{ data.description }}</em>
{{ description( name, data.description ) }}
{% endif %}
{% endmacro %}

Expand Down Expand Up @@ -112,13 +120,13 @@
{% endif %}
{% if option.note %}
<br>
<em class="[ field-list__field-group__description ]" id="description-{{ name }}-{{ option.value }}">{{ option.note }}</em>
{{ description( ( name + '-' + option.value ), option.note ) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% if data.description %}
<em class="[ field-list__field-group__description ]" id="description-{{ name }}">{{ data.description }}</em>
{{ description( name, data.description ) }}
{% endif %}
</fieldset>
{% endmacro %}
Expand Down Expand Up @@ -149,17 +157,25 @@
{% endif %}
{% if option.note %}
<br>
<em class="[ field-list__field-group__description ]" id="description-{{ name }}-{{ option.value }}">{{ option.note }}</em>
{{ description( ( name + '-' + option.value ), option.note ) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% if data.description %}
<em class="[ field-list__field-group__description ]" id="description-{{ name }}">{{ data.description }}</em>
{{ description( name, data.description ) }}
{% endif %}
</fieldset>
{% endmacro %}

{% macro description( id, html ) %}
<em class="[ field-list__field-group__description ]" id="description-{{ id }}">{{ html | safe }}</em>
{% endmacro %}

{% macro hidden_field( name, value ) %}
<input type="hidden" name="{{ name }}" id="field-{{ name }}" value="{{ value }}">
{% endmacro %}

{% macro button( text ) %}
<button type="submit" class="[ button ] [ font-base text-base weight-bold ]">{{ text }}</button>
{% endmacro %}
8 changes: 6 additions & 2 deletions src/styleguide.njk
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ permalink: /styleguide/
{% endfor %}

<h2>Forms</h2>
{% from "macros/form.njk" import label, field, textarea, confirm, select, radios, checkboxes, button %}
{% from "macros/form.njk" import label, field, textarea, confirm, select, radios, checkboxes, hidden_field, button %}
<form>
<ol class="[ field-list ]">
<li class="[ field-list__field-group ]">
Expand All @@ -125,7 +125,7 @@ permalink: /styleguide/
</li>
<li class="[ field-list__field-group ]">
{{ label("Select Label", "field-select-name") }}
{{ select( "select", [ "option 1", "option 2" ], { required: true, options_before: ["prepended option"], options_after: ["appended option"], description: "Optional description." } ) }}
{{ select( "select", [ "option 1", {label: "Option II", value: "option 2"} ], { required: true, options_before: ["prepended option"], options_after: ["appended option"], description: "Optional description." } ) }}
</li>
<li class="[ field-list__field-group field-list__field-group--confirm ]">
{{ confirm("Confirm this statement", "confirm") }}
Expand All @@ -136,6 +136,10 @@ permalink: /styleguide/
<li class="[ field-list__field-group ]">
{{ checkboxes("Checkbox Legend", "field-checkbox-name", [ "Choice 1", { label: "Choice 2", value: "Choice 2", note: "Note about choice." }, "Choice 3" ], { description: "Optional description." } ) }}
</li>
<li class="[ field-list__field-group ]">
There is a hidden field here…
{{ hidden_field("hidden-name", "hidden-value") }}
</li>
</ol>
{{ button("Button Text") }}
</form>
Expand Down