Build forms in React, without the tears 😭
APACHE-2.0 License
Bot releases are hidden (Show)
getFieldProps
now takes an object instead of just a string.unknown
type now. Please upgrade accordingly.validate
and validationSchema
no longer swallow errorsvalidationSchema
errors are no longer swallowedconst sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const validate = (values) => {
return sleep(2000).then(() => {
let errors = {};
if (['admin', 'null', 'god'].includes(values.username)) {
errors.username = 'Nice try';
}
// ...
- if (Object.keys(errors).length) {
- throw errors
- }
+ return errors;
});
};
enableReinitialize
regression in rc4. It works now.handleChange
and handleBlur
.<Field>
/useField
now handles checkboxes and multiple select like Vue, Svelte, and Angular (by binding to an array).useField()
. It will use name
, type
, and value
to figure out which props it should return to you. This enables the aforementioned new behaviors.// Single checkbox, boolean value.
<Field type="checkbox" name="newsletter" /> // => true/false
// Multiple checkboxes, bound to the same Array.
<Field type="checkbox" name="colors" value="red" />
<Field type="checkbox" name="colors" value="green" />
<Field type="checkbox" name="colors" value="blue" />
// => so if they are all checked, will be stored as
// { colors: ["red", "green", "blue"] }
// checking/unchecking will add/remove item from the array
// Single select
<Field name="car" as="select">
<option>Please select one</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</Field>
// Multiple select (bound to an Array)
<Field name="car" as="select" multiple>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</Field> // => { car: ['saab', 'opel', 'audi'] }
Commits
enableReinitialize
is true (#1570) b91a272https://github.com/jaredpalmer/formik/compare/v2.0.1-rc.4...v2.0.1-rc.5
Commits
https://github.com/jaredpalmer/formik/compare/v2.0.1-rc.3...v2.0.1-rc.4
<Field children>
warningCommits
https://github.com/jaredpalmer/formik/compare/v2.0.1-rc.2...v2.0.1-rc.3
scheduler
package to improve performance. Validation now comes in 2 flavors. Validation triggered imperatively (via validateForm
or validateField
) and prior to submit will run at the default priority (same behavior as before). Formik will now schedule validation that run as a side effect in response to calling handleChange
, setFieldValue
, setValues
, handleBlur
, setFieldTouched
, or setTouched
at low-priority. The goal is tell the browser that these validation updates should never block user input (changes to values). Since we are using scheduler
directly, it's been added to Formik's deps. For power users, you should watch Brandon Dail's React Europe talk about scheduler
.Commits
https://github.com/jaredpalmer/formik/compare/v2.0.1-rc.1...v2.0.1-rc.2
Commits
https://github.com/jaredpalmer/formik/compare/v2.0.1-rc.0...v2.0.1-rc.1
isInitialValid
method when using withFormik
Commits
isInitialValid
method when using withFormik
(#1490) b6c630dhttps://github.com/jaredpalmer/formik/compare/v1.5.6...v1.5.7
Commits
https://github.com/jaredpalmer/formik/compare/v2.0.1-alpha.5...v2.0.1-rc.0
Commits
https://github.com/jaredpalmer/formik/compare/v1.4.3...v1.4.4
Fix types for connect()
for realz.
1.5.5 vs. 1.5.6
// connect.d.ts
import * as React from 'react';
import { FormikContext } from './types';
export declare const FormikProvider: React.ProviderExoticComponent<React.ProviderProps<FormikContext<any>>>, FormikConsumer: React.ExoticComponent<React.ConsumerProps<FormikContext<any>>>;
export declare function connect<OuterProps, Values = {}>(Comp: React.ComponentType<OuterProps & {
formik: FormikContext<Values>;
-}>): any;
+}>): React.ComponentType<OuterProps>;
Commits
https://github.com/jaredpalmer/formik/compare/v1.5.5...v1.5.6
hoist-non-react-statics
@types/hoist-non-react-statics
) which caused pain and sadness for TS users. We were not really using the type defs anyways since we were casting the output to React.SFC. This was causing the type declarations to have dynamic type imports and even some triple slash directives. 😭😭😭Luckily, this is fixed now.
Commits
https://github.com/jaredpalmer/formik/compare/v1.5.4...v1.5.5
You can now nest <Formik>
/<Form>
components in React DOM. This is useful for building accessible modal forms within larger forms.
Commits
https://github.com/jaredpalmer/formik/compare/v2.0.1-alpha.4...v2.0.1-alpha.5
https://github.com/jaredpalmer/formik/compare/v2.0.1-alpha.3...v2.0.1-alpha.4
isInitialValid
and finally fixed isValid
initialXXXX
useCallback
Commits
Internally, Formik uses an undocumented utility function called setIn
to support deep state updates (and nested fields). In this release, we altered the behavior of setIn
to shallow copy unchanged siblings along the update path to be updated instead of deeply cloning the whole object.
This should enable significant performance improvements when implementing
shouldComponentUpdate
methods for nested structures as it allows direct
comparison of object / arrays to see if there has been changes to any of
their child values (because unchanged objects retain the same JS
reference).
Commits
setIn
to use clone
instead of cloneDeep
. (#1235) d34537bhttps://github.com/jaredpalmer/formik/compare/v1.5.3...v1.5.4
setIn
keeps class inheritance for the top level object (#1429) 316023bCommits
https://github.com/jaredpalmer/formik/compare/v1.5.2...v1.5.3
<Field as>
prop that passes Formik input-related props straight through.meta
object to <Field children>
with field-level metadata.enableReinitialize
regression from alpha.0<Field render>
via warning.<Field component>
via warning.alpha.0
🚨meta.touch
to meta.touched
, where meta
is the second element of the tuple returned by useField
.import React from 'react';
import { useField } from 'formik';
const MyTextField = ({ label, ...props }) => {
const [field, meta] = useField(props.name);
return (
<>
<label>
{label}
<input {...field} {...props} />
</label>
- {meta.touch && meta.error ? (
+ {meta.touched && meta.error ? (
<div className="error">{meta.error}</div>
) : null}
</>
);
};
<Field as>
and deprecate <Field component>
and <Field render>
(#1406)<Field render>