-
Notifications
You must be signed in to change notification settings - Fork 236
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
Auto data session 4 #340
Merged
Merged
Auto data session 4 #340
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8c3203d
add auto data store
joelanman b119452
add clear data link to docs app
joelanman 474a6f8
only run autodata once, include JS in docs
joelanman 0f4cae3
use 'data' hash in locals
joelanman 49637a2
use new multiple-choice css, use hyphens in names
joelanman 3fed845
store GET data
joelanman 1df56c6
seperate guidance and example pages, added h1s
joelanman 825b7a7
refactor checked function
joelanman de09e98
use list for vehicle features
joelanman 1f0cea9
fix return to examples link
joelanman 330b421
refactored docs
joelanman 34ce07c
set cookie name and timeout, use crypto
joelanman 047065a
de-duplicate forceHttps
joelanman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest this be pulled out in to a section like the other examples below.