redux-form/redux-form

Bug: submit -> submitSuccess -> reinitialize -> form.pristine == true => *edit_form* -> form.pristine == TRUE

Open

#3 729 ouverte le 4 janv. 2018

Voir sur GitHub
 (7 commentaires) (1 réaction) (0 assignés)JavaScript (12 592 stars) (1 683 forks)batch import
Version 7bughelp wanted

Description

A Possible Bug with global form pristine field

What is the current behavior?

Given reduxForm with

  1. enableReinitialize = true
  2. keepDirtyOnReinitialize = false (default)
  3. onSubmitSuccess(res, dispatch, props) { dispatch(initialize(props.form.name, props.form.values) }

After the form was successfully submitted, it reinitializes and pristine becomes true again (very good). However, after I make any alteration to the form pristine keeps staying true.

Here is what goes on in the debugger:

// createReduxForm.js: 929
const shouldUpdateInitialValues = enableReinitialize (true) && initialized(true) && deepEqual(initialValues, stateInitial) (deepEqual returns false)
// true

A combination of shouldUpdateInitialValues == true and keepDirtyOnReinitialize == false always produces pristine = true a few lines below.

If I set keepDirtyOnReinitialize to true, the pristine prop gets evaluated correctly.

I wasn't able to grasp from the documentation how keepDirtyOnReinitialize affects global pristine, because it only refers to fields' pristine.

Thanks for the awesome piece of work.

What is the expected behavior?

I expect pristine to become false after form data is changed.

Guide contributeur