Skip to content

v0.8.0

Compare
Choose a tag to compare
@jaredpalmer jaredpalmer released this 22 Jul 00:48
· 1695 commits to main since this release

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. Use setFieldValue instead.
  • Deprecate mapValuesToPayload. Move your function to the top of handleSubmit.
  • Deprecate setError escape hatch with warning. Use setStatus (it's identical and a better name IMHO).

New props and helpers 🍹 ⭐️ 🎉

  • setFieldValue: same as handleChangeValue() except it does not touch the field. Call setFieldTouched right after if you need to
  • setFieldTouched: parallel to setFieldValue, but for touched
  • setFieldError: ...yeah same thing but for errors
  • 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 an errors object or and Promise that throws an error 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