Closed moonlitgrace closed 1 year ago
You can use the Zod schema on the client as well: https://superforms.vercel.app/concepts/client-validation#realtime-validators
You can use the Zod schema on the client as well
Yea I saw that, thats helpful. I also need custom validation for password field. So is there any way to add both like
const { form, errors, enhance, constraints } = superForm(data.form, {
validationMethod: "oninput",
validators: schema && {
password: (password) => // check password with confirm password
},
});
Idk is that possible?
You can possibly do that by extending the schema: https://zod.dev/?id=extend
You can possibly do that by extending the schema
I think you didnt get me.
I'm using zxcvbn
for checking password strength on user input
like (not working) :
const { form, errors, enhance, constraints } = superForm(data.form, {
validationMethod: "oninput",
validators: schema && {
password: (password) => // check password strength with zxcvbn
},
});
I need to check password strength along with validation ??
I think you didnt get me. I need to check password strength along with validation ??
Instead of going like this. Permalink codes please :)
Hi i am the project lead. Thank you for creating superforms
So basically i wanted to ask if it was possible to validate this zod_object
in client side as well.
We will catch the error produced by this Zod
object and show some text based on this ( due to i18n )
I was wondering if this ( validation against zod
schema defined in serverside and validating it and catching error at client side ) was possible.
In simpler terms :
zod
object defined in +page.server.ts
Hello, as I said I think it's possible with extend
on the schema. Something like:
const { form, errors, enhance, constraints } = superForm(data.form, {
validationMethod: "oninput",
validators: schema.extend({
password: schema.shape.password.refine((password) => {
// Check password strength
})
}),
});
All the validation is asynchronous, so that's no problem. There is no debounce though, so if you want to delay the check, you may have to do it with on:input
. I've written a little about it here: https://superforms.vercel.app/concepts/client-validation#asynchronous-validation-and-debouncing
Thank you so much @ciscoheat ,
Its really nice to see someone responding this fast :)
I hope superforms get more adoption.
@sssuneeth please respond after you try this ( or maybe i will take a look myself 👀 ? )
Thank you, I'm glad to help. Hope your project goes well.
Hey @ciscoheat
I think it's possible with extend on the schema.
Nope, I couldnt add extend method to my schema. Anyway we finally decided to use on:input
event.
I'm closing this issue, thank you :)
Hey! I want to validate password on user input This is my password schema
And this is the validator in
+page.svelte
Earlier I tried with regex in
validators
I works fine then whats the use of theseSo, is there any way to do in
validators
without rewriting regex?