Skip to content
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

Add support for checkboxes and radio buttons #30

Merged
merged 9 commits into from
Feb 7, 2024

Conversation

helen
Copy link
Member

@helen helen commented Mar 3, 2022

Noticed while adding some requested form support that inputs with a checked state are not accounted for, as they are dropped in the field.value !== field.defaultValue check. This adds support for them! And adds checkboxes to the test. I'm not sure this is the world's most elegant approach, but I think it's easy to understand and doesn't introduce a ton of logic.

Also included is an example/test page that I made to check that this wasn't a bug caused by something else in the bigger stack. The page has a button to set the sessionStorage, as I found it difficult to debug otherwise, but not a submit button. Happy to add a submit button :)

src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@helen helen requested a review from keithamus March 10, 2022 02:36
@helen
Copy link
Member Author

helen commented Mar 10, 2022

Updated the PR to account for default checked checkboxes that get unchecked, along with a test for it. Hoping this is good to go so I can also move the work along on the actual form implementation side 🤞

src/index.ts Outdated
Comment on lines 4 to 6
function shouldResumeField(field: HTMLInputElement | HTMLTextAreaElement): boolean {
return !!field.id && field.value !== field.defaultValue && field.form !== submittedForm
return (
!!field.id &&
(field.value !== field.defaultValue ||
(field instanceof HTMLInputElement && field.checked !== field.defaultChecked)) &&
field.form !== submittedForm
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is getting pretty dense now. I wonder if we should break it up a little?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not my favorite, no, but IMO it's still okay for the moment as an iterative change. I would definitely rewrite this if we were introducing support for select elements, though. But I don't want to hold up the currently needed change/release over that :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change still considered to be viable? I'd love to see checkbox, radio, and select element support!

There's likely to be some git conflicts after #40 and #20 merge. What can I do to help ease those conflicts and support this PR's forward momentum?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanpdoyle I've added you to my fork so you can push there and keep it moving! You are also more than welcome to pull my branch into your own fork and take it from there but I figured adding you would be a quick way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@helen @theinterned I've pushed up some changes to resolve this branch's conflicts with main.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it's taken me so long to review this. I'm looking at it now

@helen helen requested a review from a team as a code owner January 26, 2024 00:56
@helen helen requested a review from dgreif January 26, 2024 00:56
@seanpdoyle seanpdoyle mentioned this pull request Feb 1, 2024
@theinterned
Copy link
Contributor

@seanpdoyle the changes make sense, however there are currently several failing tests on this branch. Can you please have a look? Thanks!

test/test.js Outdated
Comment on lines 9 to 10
<input id="my-first-field" value="first-field-value" class="js-session-resumable" />
<input id="my-second-field" value="second-field-value" class="js-session-resumable" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would guess one problem with the tests is that they are looking for input[type=text] and these are missing a type

Suggested change
<input id="my-first-field" value="first-field-value" class="js-session-resumable" />
<input id="my-second-field" value="second-field-value" class="js-session-resumable" />
<input id="my-first-field" type="text" value="first-field-value" class="js-session-resumable" />
<input id="my-second-field" type="text" value="second-field-value" class="js-session-resumable" />

@theinterned
Copy link
Contributor

UPDATE: @seanpdoyle here's a PR against this branch that fixes the tests helen#1

Copy link
Contributor

@theinterned theinterned left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @helen and @seanpdoyle for finally getting this over the finish line!

@theinterned theinterned merged commit bfb858e into github:main Feb 7, 2024
1 check passed
@seanpdoyle seanpdoyle deleted the add/checked-support branch February 7, 2024 22:43
@theinterned
Copy link
Contributor

🚀 This has shipped in v0.5.0

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.

5 participants