-
Notifications
You must be signed in to change notification settings - Fork 6
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 #1236 from nationalarchives/FCL98/transactional-li…
…cence-as-form FCL98: Transactional Licence form as Django Form.
- Loading branch information
Showing
20 changed files
with
305 additions
and
743 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
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
100 changes: 70 additions & 30 deletions
100
ds_judgements_public_ui/static/js/src/modules/transactional_licence_form.js
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 |
---|---|---|
@@ -1,44 +1,84 @@ | ||
import $ from "jquery"; | ||
|
||
/* CAUTION: This is quite a specific and brittle way of addressing these | ||
particular form fields, but Django-forms doesn't give us many | ||
other options: I haven't found a way to simply add an id or | ||
class to a single radio button or checkbox input. If the values or names | ||
of these form fields change, this code will also have to change. | ||
*/ | ||
var licenceHolderNameId = "div_id_contact-licence_holder_lastname"; | ||
var licenceHolderEmailId = "div_id_contact-licence_holder_email"; | ||
var licenceHolderControlSelector = "#div_id_contact-alternative_contact input"; | ||
var licenceHolderVisibleValue = | ||
"This is a different person (please enter their details below)"; | ||
|
||
let toggleFieldState = function (element) { | ||
if (element && element.value == licenceHolderVisibleValue) { | ||
showFields(); | ||
} else { | ||
hideFields(); | ||
} | ||
}; | ||
let setupTogglableFields = function () { | ||
/* CAUTION: This is quite a specific and brittle way of addressing these | ||
particular form fields, but Django-forms doesn't give us many | ||
other options: I haven't found a way to simply add an id or | ||
class to a single radio button or checkbox input. If the values or names | ||
of these form fields change, this code will also have to change. | ||
*/ | ||
var licenceHolderNameId = "div_id_contact-licence_holder_lastname"; | ||
var licenceHolderEmailId = "div_id_contact-licence_holder_email"; | ||
var licenceHolderControlSelector = | ||
"#div_id_contact-alternative_contact input"; | ||
var licenceHolderVisibleValue = | ||
"This is a different person (please enter their details below)"; | ||
|
||
let showFields = function () { | ||
$(licenceHolderControlSelector).attr("aria-expanded", true); | ||
$(`#${licenceHolderNameId}`).show(); | ||
$(`#${licenceHolderEmailId}`).show(); | ||
}; | ||
let toggleFieldState = function (element) { | ||
if (element && element.value == licenceHolderVisibleValue) { | ||
showFields(); | ||
} else { | ||
hideFields(); | ||
} | ||
}; | ||
|
||
let hideFields = function () { | ||
$(licenceHolderControlSelector).attr("aria-expanded", false); | ||
$(`#${licenceHolderNameId}`).hide(); | ||
$(`#${licenceHolderEmailId}`).hide(); | ||
}; | ||
let showFields = function () { | ||
$(licenceHolderControlSelector).attr("aria-expanded", true); | ||
$(`#${licenceHolderNameId}`).show(); | ||
$(`#${licenceHolderEmailId}`).show(); | ||
}; | ||
|
||
let hideFields = function () { | ||
$(licenceHolderControlSelector).attr("aria-expanded", false); | ||
$(`#${licenceHolderNameId}`).hide(); | ||
$(`#${licenceHolderEmailId}`).hide(); | ||
}; | ||
|
||
$(function () { | ||
$(licenceHolderControlSelector).attr( | ||
"aria-controls", | ||
`${licenceHolderNameId} ${licenceHolderEmailId}`, | ||
); | ||
|
||
toggleFieldState($(`${licenceHolderControlSelector}:checked`)[0]); | ||
|
||
$(licenceHolderControlSelector).change(function (event) { | ||
toggleFieldState(this); | ||
}); | ||
}; | ||
|
||
let setupPreviousButton = function () { | ||
/* | ||
This is handled with javascript for a couple of intersecting reasons. | ||
For accesibility compliance, pressing enter while on a form field should take you | ||
to the next page of the form. However, by default, pressing enter submits using the *first* | ||
button with type "submit" in the form, which in our case, would have been the "previous" button: | ||
https://stackoverflow.com/questions/48/multiple-submit-buttons-in-an-html-form | ||
One way around this is to reverse the order of the buttons in the markup, and then to float them right, | ||
however, this causes another accessibility problem: the tabbing order for those buttons is then reversed in | ||
a confusing way. | ||
To fix this, we give the "previous" button the type "button", and submit it using javascript, that way the | ||
first "submit" button in the form is the correct "default" action of going to the next page. | ||
*/ | ||
let button = document.getElementById( | ||
"transactional-licence-form-previous-button", | ||
); | ||
let form = document.getElementById("transactional-licence-form-form"); | ||
if (button) { | ||
button.style.display = "inline"; | ||
$(button).click(function (e) { | ||
e.preventDefault(); | ||
$("<input type='hidden' />") | ||
.attr("name", button.getAttribute("name")) | ||
.attr("value", button.getAttribute("value")) | ||
.prependTo(form); | ||
$(form).trigger("submit"); | ||
}); | ||
} | ||
}; | ||
|
||
$(function () { | ||
setupTogglableFields(); | ||
setupPreviousButton(); | ||
}); |
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-05-23 09:33+0000\n" | ||
"POT-Creation-Date: 2024-06-13 13:27+0000\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
@@ -74,7 +74,6 @@ msgstr "Publishing policy" | |
#: ds_judgements_public_ui/templates/pages/about_this_service.html | ||
#: ds_judgements_public_ui/templates/pages/how_to_use_this_service.html | ||
#: ds_judgements_public_ui/templates/pages/terms_of_use.html | ||
#: transactional_licence_form/templates/download.html | ||
#: transactional_licence_form/templates/start.html | ||
#: transactional_licence_form/templates/start2.html | ||
#: transactional_licence_form/templates/start3.html | ||
|
Oops, something went wrong.