Skip to content
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

added "shouldValidate" to "setValue" and "setTouched" field helpers #2371

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api/useField.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ An object that contains relevant computed metadata about a field. More specifica

An object that contains helper functions which you can use to imperatively change the value, error value or touched status for the field in question. This is useful for components which need to change a field's status directly, without triggering change or blur events.

- `setValue(value: any): void` - A function to change the field's value
- `setTouched(value: boolean): void` - A function to change the field's touched status
- `setValue(value: any, shouldValidate?: boolean): void` - A function to change the field's value. Calling this will trigger validation to run if `validateOnChange` is set to `true` (which it is by default). You can also explicitly prevent/skip validation by passing a second argument as `false`.
- `setTouched(value: boolean, shouldValidate?: boolean): void` - A function to change the field's touched status. Calling this will trigger validation to run if `validateOnBlur` is set to `true` (which it is by default). You can also explicitly prevent/skip validation by passing a second argument as `false`.
- `setError(value: any): void` - A function to change the field's error value
4 changes: 2 additions & 2 deletions packages/formik/src/Formik.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,8 @@ export function useFormik<Values extends FormikValues = FormikValues>({
const getFieldHelpers = React.useCallback(
(name: string): FieldHelperProps<any> => {
return {
setValue: (value: any) => setFieldValue(name, value),
setTouched: (value: boolean) => setFieldTouched(name, value),
setValue: (value: any, shouldValidate?: boolean) => setFieldValue(name, value, shouldValidate),
setTouched: (value: boolean, shouldValidate?: boolean) => setFieldTouched(name, value, shouldValidate),
setError: (value: any) => setFieldError(name, value),
};
},
Expand Down
4 changes: 2 additions & 2 deletions packages/formik/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ export interface FieldMetaProps<Value> {
/** Imperative handles to change a field's value, error and touched */
export interface FieldHelperProps<Value> {
/** Set the field's value */
setValue(value: Value): void;
setValue(value: Value, shouldValidate?: boolean): void;
/** Set the field's touched value */
setTouched(value: boolean): void;
setTouched(value: boolean, shouldValidate?: boolean): void;
/** Set the field's error value */
setError(value: Value): void;
}
Expand Down