-
Notifications
You must be signed in to change notification settings - Fork 85
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
Automatically apply HTML validation attributes based on zod schema #44
Comments
Along with this, it would be cool if you could give me a Something similar to remix-validity-state: https://github.com/brophdawg11/remix-validity-state#usevalidatedinput Also, note the use of "Prop Getters" over "Prop Collections": https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters (just a suggestion). Thanks! |
Hi @kentcdodds, welcome! Update1: I just notice you were reviewing conform on your stream. Thanks! and sorry that it looks confusing because I am about to release a new version (v0.4) and I have updated the examples before the doc is ready. 😅 Update2: The
Yes. The // This API is available only on pre-release (v0.4.0) due to some API changes lately.
import { getFieldsetConstraint } from '@conform-to/zod';
function LoginForm() {
const { email, password } = useFieldset(ref, {
constraint: getFieldsetConstraint(schema),
});
// ...
} I am not sure if it is worth documented because of 2 major concerns:
The usages I see for the derived constraint would be:
Do you mean an auto-generated
Thanks for the suggestion. I will definitely look into it. I don't have a good story utilizing the native constraint yet unfortunately. In long term, I will properly try building a schema validation library with a browser runtime that utilize the native constraint. But it has to wait until I lay the groundwork with the validation flow. |
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. |
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. 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 😅 |
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.
This is the same story with yup as well. Since each of them has its own validation logic, e.g. I have started working on a draft APIs for it last 2 days. I will share more details once I have a concrete proposal. 😃 |
I think this can be considered done now as we have the I am still interested in a validation solution based on the validation attributes similar to this but it is a different story in the future. |
Is it possible to have the
conform.input
utility auto-apply HTML validation attributes based on the schema?The text was updated successfully, but these errors were encountered: