Skip to content

fix(member): persist newsletter checkbox state on form re-render - #2781

Draft
mroderick wants to merge 1 commit into
masterfrom
feature/fix-newsletter-checkbox-state
Draft

fix(member): persist newsletter checkbox state on form re-render#2781
mroderick wants to merge 1 commit into
masterfrom
feature/fix-newsletter-checkbox-state

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Summary

On the member details form reached after GitHub sign-in, the "Sign up for our newsletter" checkbox lost its default checked state whenever a required field was missing and the form reloaded. The checkbox now keeps the value the user actually chose across a failed-submit reload.

Root cause: the checkbox submitted the raw string "true"/"false", which was compared against a boolean checked value and always rendered unchecked on re-render. Coercing the param to a real boolean in member_params fixes both the re-rendered state and a second latent bug - the string "false" is truthy, so unchecking the box still subscribed to the newsletter.

Fixes #2754

Manual verification

  1. Run the app locally (bundle exec rails server) and go to http://localhost:3000.
  2. Click Log in with GitHub and authenticate (or use the existing signup flow that lands on the member details form).
  3. On the details form, leave a required field empty (e.g. name) and click Save.
  4. Confirm the form reloads with the error and that the "Sign up for our newsletter" checkbox is still checked (it was unchecked before this fix).
  5. Uncheck the checkbox, leave a required field empty again, and click Save.
  6. Confirm the checkbox is still unchecked after the reload - i.e. it preserves your choice in both directions.
  7. Fill all fields, keep the checkbox checked, and submit. Confirm you reach the next step.
  8. (Optional) Repeat step 7 with the checkbox unchecked and confirm the member is not subscribed.

Tests

Added controller specs asserting the checkbox keeps its state on a failed validation, plus specs asserting subscribe/unsubscribe are called correctly for checked/unchecked submissions. Run:

bundle exec rspec spec/controllers/member/details_controller_spec.rb

Coerce the newsletter param to a real boolean so the checkbox reflects the
user's choice after a failed validation, and so unchecking actually
unsubscribes ("false" was previously truthy).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Website log in with GitHub authentication method - Newsletter sign up checkbox

1 participant