question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Automatically apply HTML validation attributes based on zod schema

See original GitHub issue

Is it possible to have the conform.input utility auto-apply HTML validation attributes based on the schema?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
edmundhungcommented, Nov 3, 2022

Most UI libraries allow you to override the ID. In any case, just because you can use a UI library that handles IDs, doesn’t mean it wouldn’t be handy to have this capability for when you’re not using a UI library for basic fields as well.

That makes sense. I will take a deeper look into the reach implementation. I think there are some limitations on these userland solutions. I might also make it a opt-in feature instead.

Seems like it’s difficult to convert a zod schema into HTML validations which is unfortunate. I may have to go with something more like remix-validity-state if that’s important to me. Still evaluating sweat_smile

This is the same story with yup as well. Since each of them has its own validation logic, e.g. ab@cd is considered a valid email in the browser but very likely not on yup or zod. I agree it would be really powerful if there is a solution that can lead the user to utilise these native browser constraint and understand when they are opting to custom validation. (e.g. In favor type and pattern to validate email instead of custom validate function).

I have started working on a draft APIs for it last 2 days. I will share more details once I have a concrete proposal. 😃

2reactions
brandonpittmancommented, Oct 28, 2022

Reach UI has an Auto ID module you could copy. I’d rather the IDs not be automatically added though, because you might be using something like React Aria that handles IDs itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema validation in TypeScript with Zod - LogRocket Blog
In this article, you will learn about schema design and validation in Zod and how to run it in a TypeScript codebase at...
Read more >
colinhacks/zod: TypeScript-first schema validation ... - GitHub
z.enum is a Zod-native way to declare a schema with a fixed set of allowable string values. Pass the array of values directly...
Read more >
Form Validation with TypeScript and Zod
This article will focus on form validation in React, but the same concepts can be applied to other frameworks (or lack thereof), and...
Read more >
Validate related schema attributes with Zod
Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data type, from a ......
Read more >
Data validation with automatic typing using zod - CodeX Team
1. Validate without description a mountain of different if, instanceof, typeof and other things. · 2. Have TypeScript types to represent the data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found