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 React Hook Form and Zod #1306

Merged
merged 23 commits into from
Sep 25, 2024
Merged

Add React Hook Form and Zod #1306

merged 23 commits into from
Sep 25, 2024

Conversation

robines
Copy link
Member

@robines robines commented Sep 2, 2024

The goal of this PR is to add the building blocks required to see if we can replace SamfForm with something more stable and easy to use. This uses React Hook Form and Zod, which are very actively developed projects. React Hook Forms adds React hooks for form management, while Zod adds schema validation with static type inference.

Notable changes:

  • Add form components from shadcn/ui (slightly adjusted)
    • This adds wrappers around React Hook Forms. See the benefits under "Features" on the page linked above
  • Add Zod error message translations with zod-i18n
  • Add example usage to Components page.
    • Relevant file to look at is ExampleForm.tsx
    • This also adds reusable Zod schema fields for username and password. More to come

Styling is NOT finalized.

Caveats:

  • Automatic form error message translations work, but only on render. Meaning if you get an error message, then change langauge, the already-rendered messages won't be translated until you force them to rerender

@robines robines requested a review from magsyg September 2, 2024 20:59
@robines robines self-assigned this Sep 2, 2024
Copy link
Contributor

@Snorre98 Snorre98 left a comment

Choose a reason for hiding this comment

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

Docs pls

Copy link
Contributor

@Snorre98 Snorre98 left a comment

Choose a reason for hiding this comment

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

For en fyr! For en PR!

@robines robines merged commit 246ad74 into master Sep 25, 2024
5 checks passed
@robines robines deleted the robin/react-hook-form branch September 25, 2024 07:45
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.

2 participants