Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of Concept - Pre-selecting components using data object #1316

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions app/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module.exports = function (env) {

------------------------------------------------------------------ */

filters.merge = (...args) => Object.assign({}, ...args)

/* ------------------------------------------------------------------
keep the following line to return your filters to the app
------------------------------------------------------------------ */
Expand Down
27 changes: 27 additions & 0 deletions app/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@
{% from "govuk/components/textarea/macro.njk" import govukTextarea %}
{% from "govuk/components/warning-text/macro.njk" import govukWarningText %}

{% set _govukCheckboxes = govukCheckboxes %}

{% macro govukCheckboxes(options) %}
{% set options = options | merge({
checkedValues: data[options.name]
}) %}
{{ _govukCheckboxes(options) }}
{% endmacro %}

{% set _govukRadios = govukRadios %}

{% macro govukRadios(options) %}
{% set options = options | merge({
checkedValue: data[options.name]
}) %}
{{ _govukRadios(options) }}
{% endmacro %}

{% set _govukSelect = govukSelect %}

{% macro govukSelect(options) %}
{% set options = options | merge({
selectedValue: data[options.name]
}) %}
{{ _govukSelect(options) }}
{% endmacro %}

{% block head %}
{% include "includes/head.html" %}
{% endblock %}
Expand Down
111 changes: 111 additions & 0 deletions app/views/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{% extends "layout.html" %}

{% block pageTitle %}
Question page template – {{ serviceName }} – GOV.UK Prototype Kit
{% endblock %}

{% block beforeContent %}
<a class="govuk-back-link" href="javascript:window.history.back()">Back</a>
{% endblock %}

{% block content %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

<form class="form" action="/test" method="post">

{{ govukCheckboxes({
idPrefix: "waste",
name: "waste",
fieldset: {
legend: {
text: "Which types of waste do you transport?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "Select all that apply."
},
items: [
{
value: "carcasses",
text: "Waste from animal carcasses"
},
{
value: "mines",
text: "Waste from mines or quarries"
},
{
value: "farm",
text: "Farm or agricultural waste"
}
]
}) }}

{{ govukRadios({
idPrefix: "where-do-you-live",
name: "where-do-you-live",
fieldset: {
legend: {
text: "Where do you live?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
items: [
{
value: "england",
text: "England"
},
{
value: "scotland",
text: "Scotland"
},
{
value: "wales",
text: "Wales"
},
{
value: "northern-ireland",
text: "Northern Ireland"
}
]
}) }}

{{ govukSelect({
id: "sort",
name: "sort",
label: {
text: "Sort by"
},
items: [
{
value: "published",
text: "Recently published"
},
{
value: "updated",
text: "Recently updated",
selected: true
},
{
value: "views",
text: "Most views"
},
{
value: "comments",
text: "Most comments"
}
]
}) }}

<button class="govuk-button" data-module="govuk-button">Continue</button>

</form>

</div>
</div>

{% endblock %}
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"express": "^4.17.1",
"express-session": "^1.13.0",
"fancy-log": "^1.3.3",
"govuk-elements-sass": "^3.1.3",
"govuk-frontend": "^4.0.1",
"govuk_frontend_toolkit": "^7.5.0",
"govuk_template_jinja": "^0.24.1",
"govuk-elements-sass": "^3.1.3",
"govuk-frontend": "github:alphagov/govuk-frontend#52ccc47b",
"gray-matter": "^4.0.3",
"gulp": "^4.0.2",
"gulp-nodemon": "^2.2.1",
Expand Down