From 31b344d6b4071dd1250dda3c445fecdedc846261 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Tue, 26 Jan 2021 15:43:59 +0000 Subject: [PATCH] Make radioSelect use GOVUK Frontend radios Includes changing the code so that the radios aren't split into two columns in the HTML present when the page loads. This layout is now added by the JS. --- app/assets/javascripts/radioSelect.js | 30 +++++++++++++-------------- app/main/forms.py | 2 +- app/templates/views/check/ok.html | 13 +++++++----- tests/javascripts/radioSelect.test.js | 24 +++++++++------------ 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/app/assets/javascripts/radioSelect.js b/app/assets/javascripts/radioSelect.js index 436397f34..cfe723158 100644 --- a/app/assets/javascripts/radioSelect.js +++ b/app/assets/javascripts/radioSelect.js @@ -10,9 +10,9 @@ 'initial': Hogan.compile(` {{#showNowAsDefault}}
-
- - +
+ +
{{/showNowAsDefault}} @@ -25,17 +25,17 @@ 'choose': Hogan.compile(` {{#showNowAsDefault}}
-
- - +
+ +
{{/showNowAsDefault}}
{{#choices}} -
- - +
+ +
{{/choices}} @@ -44,17 +44,17 @@ 'chosen': Hogan.compile(` {{#showNowAsDefault}}
-
- - +
+ +
{{/showNowAsDefault}}
{{#choices}} -
- - +
+ +
{{/choices}}
diff --git a/app/main/forms.py b/app/main/forms.py index ff4b9c6fe..9bd021a65 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -1509,7 +1509,7 @@ class ChooseTimeForm(StripWhitespaceForm): ] self.scheduled_for.categories = get_next_days_until(get_furthest_possible_scheduled_time()) - scheduled_for = RadioField( + scheduled_for = GovukRadiosField( 'When should Notify send these messages?', default='', ) diff --git a/app/templates/views/check/ok.html b/app/templates/views/check/ok.html index a72ded28b..00d400854 100644 --- a/app/templates/views/check/ok.html +++ b/app/templates/views/check/ok.html @@ -1,6 +1,5 @@ {% extends "withnav_template.html" %} {% from "components/banner.html" import banner_wrapper %} -{% from "components/radios.html" import radio_select %} {% from "components/table.html" import list_table, field, text_field, index_field, hidden_field_heading %} {% from "components/page-header.html" import page_header %} {% from "components/button/macro.njk" import govukButton %} @@ -36,10 +35,14 @@ {% if choose_time_form and template.template_type != 'letter' %} - {{ radio_select( - choose_time_form.scheduled_for, - wrapping_class='bottom-gutter-2-3' - ) }} + {{ choose_time_form.scheduled_for(param_extensions={ + 'formGroup': {'classes': 'bottom-gutter-2-3'}, + 'attributes': { + 'data-module': 'radio-select', + 'data-categories': choose_time_form.scheduled_for.categories|join(','), + 'data-show-now-as-default': 'true' + } + }) }} {% endif %} {% if (template.template_type != 'letter' or not request.args.from_test) and not letter_too_long %} {% set button_text %} diff --git a/tests/javascripts/radioSelect.test.js b/tests/javascripts/radioSelect.test.js index 8dbaf711c..767a2eb87 100644 --- a/tests/javascripts/radioSelect.test.js +++ b/tests/javascripts/radioSelect.test.js @@ -71,9 +71,9 @@ describe('RadioSelect', () => { const num = idx + 1; result += - `
- -