final-form / final-form

🏁 Framework agnostic, high performance, subscription-based form state management

Home Page:https://final-form.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FormState: Pristine calculation ignores "unregistered" fields

abrad45 opened this issue · comments

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

If initialValue.foo does not have a corresponding rendered field, changing initialValue.foo from asdf to null leaves the form in a pristine state. I think this is a bug in either the documentation or the code, but I really hope it's the code.

The documentation states:

true if the form values are the same as the initial values. false otherwise. Comparison is done with shallow-equals.

Form values may include data not currently rendered in the form (as it does in my use case).

The issue appears to happen in calculateNextFormState(). The comparison begins with registered fields, and since the field is not registered, it doesn't check to see if its value differs from what was provided in initialValues.

What is the expected behavior?

I'd expect that nulling out a part of the form's values would still calculate pristine as false.

Sandbox Link

Sandbox: https://codesandbox.io/s/react-final-form-simple-example-4vhjt

  1. Observe initialValues.middleName is set to "william"
  2. Click the "Clear middleName" button
  3. Observe that values.middleName is now null, but FormState's pristine value is still true.

What's your environment?

Newest everything

Running into this as well, any news on this?

Also running into this :(

The code sandbox link @abrad45 is unfortunately no longer valid. Please attempt with https://final-form.org/docs/final-form/types/FormState#dirty as well as pristine.