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

Use a custom form builder; introduce primer_form_for #1270

Merged
merged 21 commits into from
Aug 5, 2022

Conversation

camertron
Copy link
Contributor

In attempting to upgrade to PVC v0.0.86 in dotcom, @jonrohan and I ran into a few issues. Version 0.0.86 includes all the re-homed PRF code, which is the main source of friction.

Previously, PRF handled running Primer::Classify.call on system arguments in the Input class, which converts system arugments like ml: 3 into their corresponding CSS class counterparts. This approach works for all inputs except submit buttons, since submit buttons use Primer::ButtonComponent under the hood. The form SubmtButton is an Input, so classification happens at the Input level and then again when all the system arguments are eventually passed to Primer::ButtonComponent. In the development and test environments, classify will raise if it determines you included ml-3 in the list of classes instead of passing it as ml: 3 in the system arguments. This led to errors appearing in dotcom test output since the first classify run done in Input had already converted system arguments to class names before passing them to Primer::ButtonComponent.

I experimented a bit with a flag in the SubmitButton input that disabled classification for the system arguments attached to <input> elements, but realized the forms code runs the same classification process on system arguments attached to labels, etc. The flag seemed like an incomplete solution and a hacky one at that.

Instead I decided to introduce a custom form builder that classifies system arguments right before passing them to rails to generate the <input> elements. I also introduced a helper method, primer_form_with, that mimics rails' form_with helper but automatically uses the custom builder. This is something I've wanted to do for a long time. It also lets us set skip_default_ids automatically, which is important for a11y reasons.

@changeset-bot
Copy link

changeset-bot bot commented Aug 3, 2022

🦋 Changeset detected

Latest commit: ac3a5b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@camertron camertron temporarily deployed to github-pages August 3, 2022 18:39 Inactive
@camertron camertron temporarily deployed to github-pages August 3, 2022 21:19 Inactive
@camertron camertron marked this pull request as ready for review August 3, 2022 21:25
@camertron camertron requested review from a team, keithamus and jonrohan and removed request for keithamus August 3, 2022 21:25
@camertron camertron temporarily deployed to github-pages August 3, 2022 23:06 Inactive
@camertron camertron temporarily deployed to github-pages August 4, 2022 04:44 Inactive
@camertron camertron temporarily deployed to github-pages August 4, 2022 17:17 Inactive
@camertron camertron temporarily deployed to github-pages August 4, 2022 20:31 Inactive
@camertron camertron temporarily deployed to github-pages August 5, 2022 05:24 Inactive
@camertron camertron temporarily deployed to github-pages August 5, 2022 05:27 Inactive
@camertron camertron temporarily deployed to github-pages August 5, 2022 06:06 Inactive
@camertron camertron temporarily deployed to github-pages August 5, 2022 06:15 Inactive
@camertron camertron temporarily deployed to github-pages August 5, 2022 06:35 Inactive
@mxriverlynn mxriverlynn merged commit 4491930 into main Aug 5, 2022
@mxriverlynn mxriverlynn deleted the dont_classify_twice branch August 5, 2022 14:36
@primer-css primer-css mentioned this pull request Aug 5, 2022
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