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

USWDS - Bug: Form validation does not work within modal #5858

Open
2 tasks done
ZHeCensus opened this issue Apr 10, 2024 · 2 comments
Open
2 tasks done

USWDS - Bug: Form validation does not work within modal #5858

ZHeCensus opened this issue Apr 10, 2024 · 2 comments
Assignees
Labels
Package: Forms Package: Modal Status: Triage We're triaging this issue and grooming if necessary Type: Bug A problem in the code

Comments

@ZHeCensus
Copy link

ZHeCensus commented Apr 10, 2024

Describe the bug

When a form is within a modal and the submit button (includes data-close-modal) is clicked. Client-side validation is ignored and the modal closes without any alerts or the form submitting.

A message in the console is logged - An invalid form control with name='...' is not focusable.

#4953 Related

Steps to reproduce the bug

See https://codepen.io/zhecensus/pen/KKYRLbb

  1. Create a modal and add a form into modal__content.
  2. Add an input with a requirement
    <input minlength="4" maxlength="4" pattern="[0-9]*" />
  3. Modify the main modal button from type=button to type=submit form='formid'

  1. Fill in the form field with an invalid value
  2. Click on main modal button
    The modal should close instead of the expected behavior below

Expected Behavior

The browser's built-in validation focuses and prompts the user with an error message.
image

Related code

No response

Screenshots

image
image

System setup

Both Edge and Firefox

Additional context

This is a niche issue, and I came up with two workarounds, if this issue does not have to be resolved.

  1. Create a separate button that submits the form and leave the data-close-modal button alone. This results in two actions a user must take.
  2. Add some javascript that checks for if there is form in the modal on being toggled and does validation before closing the modal. (commented out in the codepen)

Code of Conduct

@ZHeCensus ZHeCensus added Needs: Confirmation We need to confirm that this is an issue Type: Bug A problem in the code labels Apr 10, 2024
@github-actions github-actions bot added the Status: Triage We're triaging this issue and grooming if necessary label Apr 10, 2024
@mejiaj mejiaj removed the Status: Triage We're triaging this issue and grooming if necessary label Apr 11, 2024
@mejiaj
Copy link
Contributor

mejiaj commented Apr 11, 2024

Thanks for submitting this.

We'll pull it into our current sprint to investigate this issue.

@mahoneycm
Copy link
Contributor

Thanks for the detailed issue and the code pen example @ZHeCensus !

I was able to replicate this bug using the steps outlined in the issue description in Chrome.

@mahoneycm mahoneycm added Status: Triage We're triaging this issue and grooming if necessary and removed Needs: Confirmation We need to confirm that this is an issue labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: Forms Package: Modal Status: Triage We're triaging this issue and grooming if necessary Type: Bug A problem in the code
Projects
Status: TBD
Development

No branches or pull requests

4 participants