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

bug: Required Text Input does not prevent a form from being submitted #667

Open
3 tasks done
grathomp opened this issue Oct 16, 2024 · 4 comments
Open
3 tasks done
Assignees
Labels
bug Something isn't working development Development tasks Groomed Issues that have been refined and are ready to be worked on. High Priority | Haute priorité

Comments

@grathomp
Copy link

Prerequisites | Prérequis

GC Design System Components Package and Version | Paquet et version des composants de Système de design GC

gcds-components-react": "^0.25.1

Current Behavior | Comportement observé

In version 0.15.0, when an required Input Box was in a (non-gcds) form, it would prevent submission when empty. Now it lets the form be submitted, and after submission all the 'Enter Information to continue.' errors show up.

Expected Behavior | Comportement attendu

Expected behaviour is when its a required Input Box is in a form trying to be submitted, it would prevent submission when empty.

System Info | Information sur le système

Microsoft Edge Browser, Using a react framework and version 0.25.1

Steps to Reproduce | Étapes pour reproduire le bogue

Creating a required Input box within a form

Code Reproduction URL | URL de reproduction du code

https://codesandbox.io/p/sandbox/bug-report-4d3jl9

Additional Information | Informations supplémentaires

No response

@daine daine added bug Something isn't working For Grooming labels Oct 17, 2024
@daine
Copy link
Collaborator

daine commented Oct 17, 2024

@grathomp Thanks for the report!

@daine
Copy link
Collaborator

daine commented Oct 17, 2024

@grathomp the sandbox link is broken, could you verify it's correct? TIA!

@grathomp
Copy link
Author

Try again now - I've updated permissions

@adorayi adorayi added Groomed Issues that have been refined and are ready to be worked on. and removed For Grooming labels Oct 21, 2024
@ethanWallace ethanWallace added the development Development tasks label Oct 21, 2024
@ethanWallace
Copy link
Collaborator

Hey @grathomp, since the v0.15.0 we have made some big updates to our form components. Specifically in our v0.21.0 release we transitioned to use shadow-dom and form-associated components for our form components. This change made it so we would no longer use the browser validation and rely mainly on the built in validation for each form component. The submit event on the form may fire but it does not complete as it is prevented by the form component with the error message.

If you'd like to have additional logic (validation or other use cases), here's an example of how you should be able to wait for the required form elements to be validated first, and adding your logic/code on top of that before it gets submitted to the server.

  const handleSubmit = (event: any) => {
    // Timeout for 50ms to allow components to validate
    setTimeout(() => {
      // If the nativeEvent "submit" has not been prevented
      if(!event.nativeEvent.defaultPrevented) {
        setSubmitted("true");
      }
    }, 50);
  };

@ethanWallace ethanWallace self-assigned this Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working development Development tasks Groomed Issues that have been refined and are ready to be worked on. High Priority | Haute priorité
Projects
None yet
Development

No branches or pull requests

4 participants