S
SolidJSβ€’2w ago
Garzec

Which form validation library are you using?

Coming from React I really love https://react-hook-form.com/ Are you guys using Tanstack Form for Solid or what is the "most popular" one? πŸ™‚
Performant, flexible and extensible forms with easy-to-use validation.
4 Replies
Madaxen86
Madaxen86β€’2w ago
Modular Forms: The modular and type-safe form library
Modular Forms is a JavaScript library built on SolidJS, Qwik, Preact, and React to validate and handle various types of forms.
Madaxen86
Madaxen86β€’2w ago
It’s stable and well done and has adapters for validation libraries (zod, valibot, yup,…)
Garzec
GarzecOPβ€’2w ago
thanks πŸ™‚ Unfortunately this library only supports Zod and Valibot. Would like to give ArkType a try
Madaxen86
Madaxen86β€’2w ago
Well I think you might be able to use it by passing it as the validate prop to create form. And the adapters are not that complex. E.g.
export function zodForm<TFieldValues extends FieldValues>(
schema: ZodType<any, any, TFieldValues>
): ValidateForm<TFieldValues> {
return async (values: PartialValues<TFieldValues>) => {
const result = await schema.safeParseAsync(values);
const formErrors: Record<string, string> = {};
if (!result.success) {
for (const issue of result.error.issues) {
const path = issue.path.join('.');
if (!formErrors[path]) {
formErrors[path] = issue.message;
}
}
}
return formErrors as FormErrors<TFieldValues>;
};
}
export function zodForm<TFieldValues extends FieldValues>(
schema: ZodType<any, any, TFieldValues>
): ValidateForm<TFieldValues> {
return async (values: PartialValues<TFieldValues>) => {
const result = await schema.safeParseAsync(values);
const formErrors: Record<string, string> = {};
if (!result.success) {
for (const issue of result.error.issues) {
const path = issue.path.join('.');
if (!formErrors[path]) {
formErrors[path] = issue.message;
}
}
}
return formErrors as FormErrors<TFieldValues>;
};
}

Did you find this page helpful?