validationError for client side? #96
-
Hi, thank you very much for simplify form validation in remix. This package is awesome and works really well. But in my project, i miss something. I need to validate a form client side in if (await userExistsInDatabase(username)) {
return validationError(
{
fieldErrors: {
username: "This username is already taken",
},
// 🚨 Important!
// If you're using the `subaction` prop,
// you need to specify a subaction here
// or else the errors won't be displayed.
subaction: result.data.subaction,
// You can also provide a `formId` instead of a `subaction`
// if your form has an `id` prop
formId: result.formId,
},
result.data
);
} How can i use this kind of function client side? Is that possible? It would be awesome, if i can set related field errors client and server side in the same way. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
We don't currently have an API that does this, but it would be pretty straightforward to add. On the client side we could simplify it a lot and just have a Something like this maybe? onSubmit={async (data, event, formContext) => {
const { setErrors } = formContext;
const isValid = await supabaseValidation(data);
if (!isValid) {
setErrors({ myField: 'Error!' });
event.preventDefault();
}
}} |
Beta Was this translation helpful? Give feedback.
We don't currently have an API that does this, but it would be pretty straightforward to add. On the client side we could simplify it a lot and just have a
setErrors
helper returned fromuseFormContext
. And maybe we could pass that directly toonSubmit
.Something like this maybe?