ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
32 lines • 1.24 kB
text/typescript
import { FieldValues } from 'react-hook-form';
/**
* Convert a simple validation function that returns an object matching the form shape with errors
* to a validation resolver compatible with react-hook-form.
*
* @example
* const validate = (values: { username: string }) => {
* if (values.username == null || values.username.trim() === '') {
* return { username: 'Required' };
* }
* };
*
* const validationResolver = getSimpleValidationResolver(validate);
*
* const UserForm = () => (
* <Form
* defaultValues={{ username: 'John' }}
* validationResolver={validationResolver}
* >
* <TextField source="username" />
* </Form>
* );
*/
export declare const getSimpleValidationResolver: <TFieldValues extends FieldValues = FieldValues>(validate: ValidateForm<TFieldValues>) => (data: TFieldValues) => Promise<{
values: TFieldValues;
errors: {};
} | {
values: {};
errors: any;
}>;
export type ValidateForm<TFieldValues extends FieldValues = FieldValues> = (data: TFieldValues) => Partial<Record<keyof TFieldValues, any>> | undefined | Promise<Partial<Record<keyof TFieldValues, any>> | undefined>;
//# sourceMappingURL=getSimpleValidationResolver.d.ts.map