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

forms immediate server side validation #1672

Merged
merged 15 commits into from
Dec 8, 2022

Conversation

neall
Copy link
Contributor

@neall neall commented Dec 5, 2022

Description

This adds optional client-side functionality to Forms framework text fields so they can validate against the server as the user types.

immediate-validation

I had to touch a lot of lines in form_control.html.erb, so I wrapped that in some more tests. There's still a lot of logic in that file but I moved some of it into other places where it is easier to read.

In particular that file is where we render the error-message-related elements. We normally don't render them if there is no error on the field, but if we are using auto-check and updating the client we need to render those elements hidden.

Integration

This won't require any changes to existing forms; nothing changes unless the developer specifies a URL for auto_check_src on their text field.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews

@neall neall requested review from a team and keithamus December 5, 2022 21:34
@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2022

🦋 Changeset detected

Latest commit: 3fd3217

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

@github-actions github-actions bot added the javascript Pull requests that update Javascript code label Dec 5, 2022
@neall neall temporarily deployed to github-pages December 5, 2022 21:39 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2022

⚠️ Visual differences found

Our visual comparison tests found UI differences. Please review the differences by viewing the files changed tab to ensure that the changes were intentional.

Review visual differences

Copy link
Contributor

@camertron camertron left a comment

Choose a reason for hiding this comment

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

Yasss! 🎉 Just a few minor things.

test/lib/primer/forms/deep_thought.rb Outdated Show resolved Hide resolved
test/lib/primer/forms/forms_test.rb Outdated Show resolved Hide resolved
@camertron camertron temporarily deployed to review-pr-1672 December 6, 2022 00:01 Inactive
@camertron camertron temporarily deployed to github-pages December 6, 2022 00:05 Inactive
@lesliecdubs
Copy link
Member

Oh, this is neat! Was there an issue tied to this effort? Curious if we involved Primer accessibility design in the decisions about how the client-side validations appear in the form.

@camertron
Copy link
Contributor

@lesliecdubs good questions! There's no tracking issue to my knowledge. This work came from one of the settings page forms @neall's been working on. It so happens I also need it for the billing upgrade form.

Curious if we involved Primer accessibility design in the decisions about how the client-side validations appear in the form.

We have not explicitly sought their input, however the markup and behavior adheres to the existing form interface guidelines. I believe they have been a11y reviewed, although I may be wrong about that.

In any case, we do need to have someone from a11y look at this. We probably need to announce the validation message somehow.

@neall neall force-pushed the neall/forms-immediate-server-side-validation branch from 53228a3 to 683c2b4 Compare December 6, 2022 21:14
@neall neall force-pushed the neall/forms-immediate-server-side-validation branch from f9431ec to 21c6f3c Compare December 6, 2022 21:19
@neall neall force-pushed the neall/forms-immediate-server-side-validation branch from 81efead to 025d7c0 Compare December 7, 2022 14:00
@neall neall temporarily deployed to github-pages December 7, 2022 14:06 — with GitHub Actions Inactive
@neall neall force-pushed the neall/forms-immediate-server-side-validation branch from 05b5421 to 5bad56d Compare December 7, 2022 14:14
@neall neall temporarily deployed to github-pages December 7, 2022 14:18 — with GitHub Actions Inactive
@neall neall force-pushed the neall/forms-immediate-server-side-validation branch from 44ee351 to e3a9f01 Compare December 7, 2022 14:23
@neall neall temporarily deployed to github-pages December 7, 2022 14:27 — with GitHub Actions Inactive
@neall neall temporarily deployed to github-pages December 7, 2022 15:15 — with GitHub Actions Inactive
@neall neall temporarily deployed to review-pr-1672 December 7, 2022 18:38 — with GitHub Actions Inactive
@neall neall temporarily deployed to github-pages December 7, 2022 18:42 — with GitHub Actions Inactive
@neall neall temporarily deployed to review-pr-1672 December 7, 2022 19:38 — with GitHub Actions Inactive
@neall neall temporarily deployed to github-pages December 7, 2022 19:43 — with GitHub Actions Inactive
Copy link
Contributor

@camertron camertron left a comment

Choose a reason for hiding this comment

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

🎉

@neall neall changed the title Neall/forms immediate server side validation forms immediate server side validation Dec 7, 2022
neall and others added 13 commits December 8, 2022 10:21
This sets up a place to test form text fields that will automatically
validate against the server. It makes tests around the existing text
field functionality without the auto-server-validation.

I pulled out the DeepMind fake model from an existing test file in order
to share it with this new test file.
This will allow us to validate a text field against the server with
JavaScript using custom elements.
When we show the validation elements, only include the data-target
attributes when we need them.
We decided that `text-field` was a bit too generic a name for the global
custom element namespace on a page.
Prevent PrimerTextField event handlers from hanging around in weird
cases.

Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
We were only deploying lib assets under `lib/postcss_mixins`, but now we
have JavaScript coming from the lib directory as well.
The underlying functionality is tested somewhere else, and these example
forms are not used in the built gem.
Terser seems to be eliminating debugger statements during minification
and we couldn't figure out why. For now, if you want to use the debugger
in development you can comment out the line that adds the Terser plugin
to Rollup.
@neall neall force-pushed the neall/forms-immediate-server-side-validation branch from c352bf6 to 33acbe2 Compare December 8, 2022 15:23
@neall neall temporarily deployed to review-pr-1672 December 8, 2022 15:23 — with GitHub Actions Inactive
@neall neall temporarily deployed to github-pages December 8, 2022 15:27 — with GitHub Actions Inactive
@camertron camertron temporarily deployed to github-pages December 8, 2022 20:11 — with GitHub Actions Inactive
@camertron camertron merged commit 1a7dadd into main Dec 8, 2022
@camertron camertron deleted the neall/forms-immediate-server-side-validation branch December 8, 2022 21:25
@primer-css primer-css mentioned this pull request Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants