davidkpiano / react-redux-form

Create forms easily in React with Redux.
https://davidkpiano.github.io/react-redux-form
MIT License
2.06k stars 252 forks source link

Form not submitting when using form validator and custom reducer #1059

Open AxoInsanit opened 6 years ago

AxoInsanit commented 6 years ago

The Problem

When using a custom reducer AND a form level validator the form does not submit

Steps to Reproduce

If you set up a custom reducer in createForms AND also the form has a form level validator, the form wont submit

const store = createStore(
  combineReducers({
    // ... use createForms, which will create:
    // the model reducer at "user"
    // the forms reducer at "forms" (e.g., "forms.user")
    ...createForms({
      user: customReducerUserState,
      user2: initialUserState2
    })
  }),
  composeEnhancers()
);
    const passwordsMatch = val => {
      // console.log('val',val);
      return true;
    };
<Form
          model="user"
          onSubmit={v => console.log("submit", v)}
          validators={{
            "": { passwordsMatch }
          }}
        >

Expected Behavior

The form should submit :)

Actual Behavior

It doesnt

Reproducible Code Example

https://codesandbox.io/s/llo0jrpyq9

davidkpiano commented 6 years ago

Is there any way you can avoid using Immutable?

AxoInsanit commented 6 years ago

Not really, no

On Thu, Jan 4, 2018 at 8:29 PM David Khourshid notifications@github.com wrote:

Is there any way you can avoid using Immutable?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/davidkpiano/react-redux-form/issues/1059#issuecomment-355456862, or mute the thread https://github.com/notifications/unsubscribe-auth/ADCSPwzwUPkiymA2GLtgvM7SvKWU8I8Dks5tHYkPgaJpZM4RT2ao .

AxoInsanit commented 6 years ago

is this a known issue? is there a way to make this work without getting rid of immutable?

BTW, thanks for all the great work!

davidkpiano commented 6 years ago

When I got rid of immutable, it worked as expected. In the next version (or a future form library that improves over react-redux-form) I would recommend not using Immutable.JS. Working with ad-hoc data structures is a major pain point and creates unnatural, hard-baked dependencies. I recommend working with something like https://github.com/mweststrate/immer or https://github.com/aearly/icepick instead.

AxoInsanit commented 6 years ago

Thanks for the recommendation, sadly in this case we already have a lot of code tied to immutable as well as RRF. is this something fixable (should I attempt a PR?, where should I start looking?) or is tied to architectural stuff ?

davidkpiano commented 6 years ago

should I attempt a PR?

Yes please. PRs always welcome, and I get around to reviewing/accepting/releasing them much, much faster than fixing it myself, due to time constraints.