fix(member): persist newsletter checkbox state on form re-render - #2781
Draft
mroderick wants to merge 1 commit into
Draft
fix(member): persist newsletter checkbox state on form re-render#2781mroderick wants to merge 1 commit into
mroderick wants to merge 1 commit into
Conversation
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).
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 inmember_paramsfixes 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
bundle exec rails server) and go tohttp://localhost:3000.Tests
Added controller specs asserting the checkbox keeps its state on a failed validation, plus specs asserting
subscribe/unsubscribeare called correctly for checked/unchecked submissions. Run: