-
Notifications
You must be signed in to change notification settings - Fork 8
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
Terms of service checkbox bug #3237
Conversation
@@ -29,7 +29,7 @@ | |||
<li>checking you’re safe to work with children</li> | |||
</ul> | |||
|
|||
<%= f.govuk_check_box :accept_ts_and_cs, true, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %> | |||
<%= f.govuk_check_box :accept_ts_and_cs, @sign_up_form.accept_ts_and_cs, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %> |
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.
This solves the bug, but I'm not convinced it is the correct solution. I've had a look through the docs which suggests that this is the attribute for controlling the checkbox value.
But having a look at other checkboxes in the codebase, we haven't implemented similar changes elsewhere. The second attribute is left as true
rather than taking in the property on the object.
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.
'true'
seems to work just as well
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.
'true'
does work on the page but I ran in to some difficulty when writing the tests.
Both true
and 'true'
add a value='true'
attribute to the input element in both the unchecked and checked states, which meant that you couldn't distinguish between the states for the test. I don't really understand how it is working on the page.
@sign_up_form.accept_ts_and_cs
only adds value='on'
in the checked state, which is means we can test it easily and it is easier to reason about how it is working.
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.
Took me a bit to understand this!
For my understanding: what the form builder does is compare @sign_up_form.accept_ts_and_cs
with whatever is the second argument to govuk_check_box
.
- When we use the boolean
true
, the boolean is cast to the string"true"
as thevalue=
. This means that the for comparestrue == "true"
- When we use
"true"
or any other string, it will work because we compare the the correct things - When we use
@sign_up_form.accept_ts_and_cs
, this is initially nil, so novalue=
is provided. When submitting we then submit the string "on
", which is compared correctly again
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.
Discussed offline, LGTM once we add a system spec 👍
@@ -29,7 +29,7 @@ | |||
<li>checking you’re safe to work with children</li> | |||
</ul> | |||
|
|||
<%= f.govuk_check_box :accept_ts_and_cs, true, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %> | |||
<%= f.govuk_check_box :accept_ts_and_cs, @sign_up_form.accept_ts_and_cs, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %> |
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.
'true'
seems to work just as well
1bb2340
to
febd895
Compare
end | ||
|
||
def and_the_ts_and_cs_are_still_checked | ||
expect(find_field(t('authentication.sign_up.accept_terms_checkbox')).value).to eq 'on' |
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.
Capybara has a cool helper for this:
expect(find_field(t('authentication.sign_up.accept_terms_checkbox')).value).to eq 'on' | |
expect(page).to have_checked_field t('authentication.sign_up.accept_terms_checkbox') |
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.
Thanks, I've added that in now
@@ -29,7 +29,7 @@ | |||
<li>checking you’re safe to work with children</li> | |||
</ul> | |||
|
|||
<%= f.govuk_check_box :accept_ts_and_cs, true, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %> | |||
<%= f.govuk_check_box :accept_ts_and_cs, @sign_up_form.accept_ts_and_cs, multiple: false, link_errors: true, label: { text: t('authentication.sign_up.accept_terms_checkbox') } %> |
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.
Took me a bit to understand this!
For my understanding: what the form builder does is compare @sign_up_form.accept_ts_and_cs
with whatever is the second argument to govuk_check_box
.
- When we use the boolean
true
, the boolean is cast to the string"true"
as thevalue=
. This means that the for comparestrue == "true"
- When we use
"true"
or any other string, it will work because we compare the the correct things - When we use
@sign_up_form.accept_ts_and_cs
, this is initially nil, so novalue=
is provided. When submitting we then submit the string "on
", which is compared correctly again
febd895
to
b73ce0b
Compare
Thanks @tijmenb for explaining what is going on and for raising the issue in the form builder repo. I've tidied up my commits and tested it all and so I think this is now ready to merge in. |
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.
👍 Nice, thanks!
Context
The terms of service checkbox doesn't persist answer if there is a validation error with the email address on the sign up page.
Changes proposed in this pull request
Edit the sign up form template to read in the
@sign_up_form
object for the checkbox value.Guidance to review
To test this manually:
Link to Trello card
https://trello.com/c/zWvC0NDW/2035-bug-terms-of-service-checkbox-doesnt-persist-answer-if-there-is-a-validation-error-with-the-email-address
Things to check