v0.8.0
tl;dr
- No breaking changes, but a few deprecation warnings.
- New names for some imperative setters
validationSchema
and Yup are now 100% optional- New
validate
method can handle sync and async custom validators - More control over when validation is run
Deprecations (console warnings right now) 🗑
- Deprecate
handleChangeValue
. UsesetFieldValue
instead. - Deprecate
mapValuesToPayload
. Move your function to the top ofhandleSubmit
. - Deprecate
setError
escape hatch with warning. UsesetStatus
(it's identical and a better name IMHO).
New props and helpers 🍹 ⭐️ 🎉
setFieldValue
: same ashandleChangeValue()
except it does not touch the field. CallsetFieldTouched
right after if you need tosetFieldTouched
: parallel tosetFieldValue
, but fortouched
setFieldError:
...yeah same thing but forerrors
submitForm: () => void;
which lets you submit your form without a dom event (very useful for testing). s/o @ctrlplusb for seeing this as missing way before I did.dirty: boolean
as computed prop.true
if anything has been touched.status?: any
&setStatus: (status: any) => void
An escape hatch helper for when you need to set arbitrary state (like a success behavior)
New Formik configuration options ⚙️
-
validate?: (values: Values, props: Props) => { [field: string]: string } | Promise<any>
Optional custom validation option. Either return anerrors
object or and Promise that throws anerror
object. -
validateOnChange?: boolean = false
. Will fire off validation on change events. -
validateOnBlur?: boolean = true
. Will fire off validation on blur events. -
moar tests! (like a lot lot lot more)
-
validationSchema
is now optional.
Even more badass TypeScript support 🎉
See #74 for details.
I added type safety to all the new setters by restricting their respective keys to Values
by using mapped types. As a result, instead of being able to set arbitrary keys on errors
and touched
, all the setters will now get angry if field(s) are not found in your Values
interface.
Old
interface FormikValues {
[field: string]: any;
}
interface FormikErrors {
[field: string]: string;
}
interface FormikTouched {
[field: string]: boolean;
}
New
export interface FormikValues {
[field: string]: any;
}
export type FormikErrors<Values extends FormikValues> = {
[Key in keyof Values]?: string
};
export type FormikTouched<Values extends FormikValues> = {
[Key in keyof Values]?: boolean
};
-Jared