-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[v2]: Explore adding debounceValidateMs
prop
#1526
Comments
+1, would totally like to see that |
Any updates on this? |
+1. this is a really nice to have feature |
I think validation can be a little more granular than this. Along with the theme of creating "bindings" for validators like Yup, I think we can also create default bindings for the default Formik validators -- FormValidator and FieldValidator, then we can compose this and let users wrap it with whatever they want to. This is how I'd handle it in my V3 reducer refs branch: import { FormValidator, FieldValidator } from 'formik';
import { YupValidator } from '@formik/yup';
type ValidationHandler<Values extends FormikValues> = (
getState: () => FormikState,
dispatch: React.Dispatch<FormikMessage>
) => Promise<FormikErrors<Values>>;
export const defaultValidator: ValidationHandler<Values> = (getState, dispatch) => {
return Promise.all([
FormValidator(getState, dispatch),
FieldValidator(getState, dispatch),
YupValidator(getState, dispatch),
]);
};
// in Formik
const runAllValidations = const useEventCallback(
() => (props.validationHandler ?? defaultValidator)(getState, dispatch),
[props.validationHandler, defaultValidator, getState, dispatch]
);
// in userland
import { Formik, defaultValidationHandler } from 'formik';
const myForm = () => {
const validationHandler = useDebounce(defaultValidationHandler, 300);
return <Formik validationHandler={validationHandler} validate={() => console.log('this API doesn't change, it is what FormValidator uses')} />
} (eventually we would deprecate YupValidator from defaultValidator, and @formik/yup would expose a YupValidationHandler which includes the YupValidator) |
This prop would take a number as a prop and internally Formik would debounce all non-submit-related validation calls.
The text was updated successfully, but these errors were encountered: