-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from alphagov/auto-data-session-4
Auto data session 4
- Loading branch information
Showing
15 changed files
with
605 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* global $ */ | ||
$('body').on('submit', 'form', function (e) { | ||
// On form submit, add hidden inputs for checkboxes so the server knows if | ||
// they've been unchecked. This means we can automatically store and update | ||
// all form data on the server, including checkboxes that are checked, then | ||
// later unchecked | ||
|
||
var $checkboxes = $(this).find('input:checkbox') | ||
|
||
var $inputs = [] | ||
var names = {} | ||
|
||
$checkboxes.each(function () { | ||
var $this = $(this) | ||
|
||
if (!names[$this.attr('name')]) { | ||
names[$this.attr('name')] = true | ||
var $input = $('<input type="hidden">') | ||
$input.attr('name', $this.attr('name')) | ||
$input.attr('value', '_unchecked') | ||
$inputs.push($input) | ||
} | ||
}) | ||
|
||
$(this).prepend($inputs) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Example - Passing data | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<main id="content" role="main"> | ||
|
||
{% include "includes/breadcrumb_examples.html" %} | ||
|
||
<div class="grid-row"> | ||
<div class="column-two-thirds"> | ||
|
||
<h1 class="heading-xlarge"> | ||
Passing data from page to page | ||
</h1> | ||
|
||
<p> | ||
You may want to use or display data a user has entered over a few screens. The kit automatically stores all data entered, so you can show it later. | ||
</p> | ||
|
||
<p> | ||
To clear the data (for example at the end of a user research session) click the "Clear data" link in the footer. | ||
</p> | ||
|
||
<p> | ||
<a href="/docs/examples/pass-data/vehicle-registration">You can see an example here.</a> | ||
</p> | ||
|
||
<p> | ||
The code for the example is in this folder in the prototype kit: | ||
</p> | ||
|
||
<pre> | ||
<div class="code"> | ||
/docs/views/examples/pass-data | ||
|
||
</div> | ||
</pre> | ||
|
||
<h2 class="heading-medium">How to use</h2> | ||
|
||
<p>The kit stores data from inputs using the name attribute of the input.</p> | ||
|
||
<p>For example, if you have this input:</p> | ||
|
||
<pre> | ||
<div class="code"> | ||
<input name="first-name"> | ||
|
||
</div> | ||
</pre> | ||
|
||
<p>You can show what the user entered later on like this:</p> | ||
|
||
<pre> | ||
<div class="code"> | ||
<p>{%raw%}{{ data['first-name'] }}{%endraw%}</p> | ||
|
||
</div> | ||
</pre> | ||
|
||
|
||
<h3 class="heading-small"> | ||
Clearing data | ||
</h3> | ||
|
||
<p> | ||
To clear the data (for example at the end of a user research session) click the "Clear data" link in the footer. | ||
</p> | ||
|
||
<h3 class="heading-small"> | ||
Showing answers in inputs | ||
</h3> | ||
|
||
<p> | ||
If a user goes back to a page where they entered data, they would expect to see the answer they gave. | ||
</p> | ||
|
||
<p>For a text input:</p> | ||
<pre> | ||
<div class="code"> | ||
<input name="first-name" value="{%raw%}{{ data['first-name'] }}{%endraw%}"> | ||
|
||
</div> | ||
</pre> | ||
|
||
<p>For a radio or checkbox input you need to use the 'checked' function:</p> | ||
<pre> | ||
<div class="code"> | ||
<input type="radio" name="over-18" value="yes" {%raw%}{{ checked('over-18','yes') }}{%endraw%}> | ||
|
||
</div> | ||
</pre> | ||
|
||
<h2 class="heading-medium">Advanced features</h2> | ||
|
||
<h3 class="heading-small"> | ||
Using the data on the server | ||
</h3> | ||
|
||
<p>You can access the data on the server in a route, for example for an input with name="first-name":</p> | ||
|
||
<pre> | ||
<div class="code"> | ||
var firstName = req.session.data['first-name'] | ||
|
||
</div> | ||
</pre> | ||
|
||
<h3 class="heading-small"> | ||
Ignoring inputs | ||
</h3> | ||
|
||
<p>To prevent an input being stored, use an underscore at the start of the name.</p> | ||
|
||
<pre> | ||
<div class="code"> | ||
<input name="_secret"> | ||
|
||
</div> | ||
</pre> | ||
|
||
</div> | ||
</div> | ||
</main> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Check your answers | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<main id="content" role="main"> | ||
|
||
<div class="grid-row"> | ||
<div class="column-two-thirds"> | ||
<h1 class="heading-large"> | ||
Check your answers before sending your application | ||
</h1> | ||
|
||
<div class="form-group"> | ||
|
||
<table class="check-your-answers"> | ||
|
||
<thead> | ||
<tr> | ||
<th colspan="2"> | ||
<h2 class="heading-medium"> | ||
Vehicle details | ||
</h2> | ||
</th> | ||
<th> | ||
</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<tr> | ||
<td> | ||
Registration number | ||
</td> | ||
<td> | ||
{{data['vehicle-registration']}} | ||
</td> | ||
<td class="change-answer"> | ||
<a href="/docs/examples/pass-data/vehicle-registration"> | ||
Change <span class="visuallyhidden">registration number</span> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
Vehicle type | ||
</td> | ||
<td> | ||
{{data['vehicle-type']}} | ||
</td> | ||
<td class="change-answer"> | ||
<a href="/docs/examples/pass-data/vehicle-type"> | ||
Change <span class="visuallyhidden">vehicle type</span> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
Vehicle features | ||
</td> | ||
<td> | ||
<ul> | ||
{% for feature in data['vehicle-features'] %} | ||
<li>{{ feature }}</li> | ||
{% else %} | ||
<li>No features selected</li> | ||
{% endfor %} | ||
</ul> | ||
</td> | ||
<td class="change-answer"> | ||
<a href="/docs/examples/pass-data/vehicle-features"> | ||
Change <span class="visuallyhidden">vehicle features</span> | ||
</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<p> | ||
<a href="/docs/tutorials-and-examples"> | ||
Return to prototype kit examples | ||
</a> | ||
</p> | ||
</div> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
</main> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Example - Passing data | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<main id="content" role="main"> | ||
|
||
{% include "includes/breadcrumb_examples.html" %} | ||
|
||
<div class="grid-row"> | ||
<div class="column-two-thirds"> | ||
|
||
<form action="/docs/examples/pass-data/vehicle-check-answers" method="post" class="form"> | ||
|
||
<h1 class="heading-medium"> | ||
Which of these applies to your vehicle? | ||
</h1> | ||
|
||
<div class="form-group"> | ||
<fieldset> | ||
|
||
<legend class="visuallyhidden"> | ||
Which of these applies to your vehicle? | ||
</legend> | ||
|
||
<p> | ||
Select all that apply | ||
</p> | ||
|
||
<div class="multiple-choice"> | ||
<input id="vehicle-feature-heated-seats" name="vehicle-features" type="checkbox" value="Heated seats" {{ checked("vehicle-features", "Heated seats") }}> | ||
<label for="vehicle-feature-heated-seats">Heated seats</label> | ||
</div> | ||
|
||
<div class="multiple-choice"> | ||
<input id="vehicle-feature-gps" name="vehicle-features" type="checkbox" value="GPS" {{ checked("vehicle-features", "GPS") }}> | ||
<label for="vehicle-feature-gps">GPS</label> | ||
</div> | ||
|
||
<div class="multiple-choice"> | ||
<input id="vehicle-feature-radio" name="vehicle-features" type="checkbox" value="Radio" {{ checked("vehicle-features", "Radio") }}> | ||
<label for="vehicle-feature-radio">Radio</label> | ||
</div> | ||
|
||
</fieldset> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="submit" class="button" value="Continue"> | ||
</div> | ||
|
||
</form> | ||
|
||
</div> | ||
</div> | ||
</main> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Example - Passing data | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<main id="content" role="main"> | ||
|
||
{% include "includes/breadcrumb_examples.html" %} | ||
|
||
<div class="grid-row"> | ||
<div class="column-two-thirds"> | ||
|
||
<form action="/docs/examples/pass-data/vehicle-type" method="post" class="form"> | ||
|
||
<h1 class="heading-medium"> | ||
What is your vehicle registration number? | ||
</h1> | ||
|
||
<div class="form-group"> | ||
<fieldset> | ||
|
||
<legend class="visuallyhidden"> | ||
What is your vehicle registration number? | ||
</legend> | ||
|
||
<label class="visually-hidden" for="registration-number">Vehicle registration number</label> | ||
<input class="form-control" id="registration-number" name="vehicle-registration" type="text" value="{{data['vehicle-registration']}}"> | ||
|
||
</fieldset> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="submit" class="button" value="Continue"> | ||
</div> | ||
|
||
</form> | ||
|
||
</div> | ||
</div> | ||
</main> | ||
{% endblock %} |
Oops, something went wrong.