Formik: To add dirty/pristine field property to 'FieldMetaProps'

Created on 16 Nov 2020  路  4Comments  路  Source: formium/formik

馃殌 Feature request

Current Behavior

You have to use your own method to determine if a field has a changed value on a field level.

Desired Behavior

To be able to check in FieldMetaProps whether or not the field's value has been altered.

Suggested Solution

Do a comparison on field level to check whether or not the field is dirty/pristine. Perhaps the same method as in the comparison at form level can be used which calculates that dirty value.

Who does this impact? Who is this for?

Everyone who wants to check whether or not a field still has the original value.

Describe alternatives you've considered

I am using a comparison on field level in my components:

if (touched && JSON.stringify(value) !== JSON.stringify(initialValue)) {
   // this field is dirty
}
// Or better yet instead of JSON.stringify use an object-diff library for this comparison.
// Formik uses isEqual from react-fast-compare
FastField Field Enhancement

Most helpful comment

+1 will add to v3.

All 4 comments

Relates to #1364 #1421

+1 will add to v3.

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days

Any update on when is this going to be available?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredpalmer picture jaredpalmer  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

giulioambrogi picture giulioambrogi  路  3Comments

outaTiME picture outaTiME  路  3Comments

Jungwoo-An picture Jungwoo-An  路  3Comments