Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when used with redux-form #119

Open
nikksan opened this issue Aug 23, 2018 · 5 comments
Open

Issue when used with redux-form #119

nikksan opened this issue Aug 23, 2018 · 5 comments

Comments

@nikksan
Copy link

nikksan commented Aug 23, 2018

I have a form which I want to validate on the client side, aswell as on the server side. The client side validation is handled by the redux-form package and the server side is handled using regux-logic.
In order to trigger the the redux form error I must throw SubmissionError, however if I try to do that in the process method the error is thrown on the global scope and is not handled by the redux-form.

Here is how my logic looks like:

const formSubmitLogic = createLogic({
  type: SUBMIT_FORM,
  latest: true,
  async process({ action }, dispatch, done) {
    try {
      await Api.submitForm(action.form);
    } catch (err) {
      throw new SubmissionError(err);
    }
    
    done();
  },
});
@nikksan
Copy link
Author

nikksan commented Aug 23, 2018

I eventually fixed it. The issue turned out to be more related to the redux-form package, rather than redux-logic

@mihaisavezi
Copy link

@nikksan How did you fix it, I am running into the same problem

@mihaisavezi
Copy link

mihaisavezi commented Oct 5, 2018

If anyone else had this problem, you don't actually throw a SubmissionError. But I use redux-api-middleware with this package. You can use one of the actionCreators in the library. I just call stopSubmit('formName', errorObject) like this:

import { stopSubmit } from 'redux-form/immutable';

...

export const loginErrorLogic = createLogic({
  type: types.LOGIN_USER_ERROR,
  latest: true,
  process({ action }, dispatch, done) {

    if (action.payload.response.error === 'invalid_credentials') {
      dispatch(
        stopSubmit('login', {
          _error: 'Email address and password do not match.',
        }),
      );
    }
    done();
  },
});

@jeffbski
Copy link
Owner

jeffbski commented Oct 7, 2018

Thanks for providing the followup @mihaisavezi

I haven't used redux-form in a while, I've been using formik these days since it is easier to test with (no need to setup a store).

https://github.com/jaredpalmer/formik

@Adiqq
Copy link

Adiqq commented Mar 20, 2019

@jeffbski Can we have some example of how to use redux-logic with formik and yup? Especially how to integrate validation? Should validation at redux-logic be skipped altogether?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants