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

V6 RC2 - change prop is not bound to dispatch #1247

Closed
esamattis opened this issue Jun 30, 2016 · 7 comments
Closed

V6 RC2 - change prop is not bound to dispatch #1247

esamattis opened this issue Jun 30, 2016 · 7 comments

Comments

@esamattis
Copy link
Contributor

The documentation states that the action creators are bound to the Redux dispatch but it doesn't seem to be the case with change function.

This does not work

this.props.change("fieldName", "new value");

But this works

this.props.dispatch(this.props.change("fieldName", "new value"));
@dmeenhuis
Copy link
Contributor

I've updated to RC2 this morning and it seems this problem still exists.

@esamattis esamattis changed the title V6 alpha15 - change prop is not bound to dispatch V6 RC" - change prop is not bound to dispatch Jul 6, 2016
@esamattis esamattis changed the title V6 RC" - change prop is not bound to dispatch V6 RC2 - change prop is not bound to dispatch Jul 6, 2016
@wesleycyu
Copy link

In 6.0.0-alpha.6 even this.props.dispatch(this.props.change("fieldName", "new value")); doesn't work.

This is because change is incorrectly returning

{
   type: "redux-form/CHANGE",
   value: "fieldName",
   touch: false,
   form: "formName"
}

Instead of:

{
   type: "redux-form/CHANGE",
   field: "fieldName",
   value: "new_value",
   touch: false,
   form: "formName"
}

It's missing the field attribute and mis-assigning the value attribute.

@yormi
Copy link

yormi commented Aug 30, 2016

Ok guys ! After spending to much time on my problem, I finally end-up with the same conclusion with v6.0.1:

  • The change is not bound to dispatch as written in the doc but instead returns the action.
  • However, the action has been fixed regarding the mis-assigning mentionned by @wesleycyu !
  • The focus function is not in the doc but in the code. If blur is exposed shouldn't focus be too ?

@erikras What do you think ? Should the doc be changed so it won't say that blur and change are 2 "bound action creator, so it returns nothing". Or the opposite and the code be added the bindActionCreators there:

const bindForm = actionCreator => actionCreator.bind(null, initialProps.form)

            // Bind the first parameter on `props.form`
            const boundFormACs = mapValues(formActions, bindForm)
            const boundArrayACs = mapValues(arrayActions, bindForm)
            const boundBlur = (field, value) => blur(initialProps.form, field, value, !!initialProps.touchOnBlur)
            const boundChange = (field, value) => change(initialProps.form, field, value, !!initialProps.touchOnChange)
            const boundFocus = bindForm(focus)

            // Wrap action creators with `dispatch`
            const connectedFormACs = bindActionCreators(boundFormACs, dispatch)
            const connectedArrayACs = {
              insert: bindActionCreators(boundArrayACs.arrayInsert, dispatch),
              move: bindActionCreators(boundArrayACs.arrayMove, dispatch),
              pop: bindActionCreators(boundArrayACs.arrayPop, dispatch),
              push: bindActionCreators(boundArrayACs.arrayPush, dispatch),
              remove: bindActionCreators(boundArrayACs.arrayRemove, dispatch),
              removeAll: bindActionCreators(boundArrayACs.arrayRemoveAll, dispatch),
              shift: bindActionCreators(boundArrayACs.arrayShift, dispatch),
              splice: bindActionCreators(boundArrayACs.arraySplice, dispatch),
              swap: bindActionCreators(boundArrayACs.arraySwap, dispatch),
              unshift: bindActionCreators(boundArrayACs.arrayUnshift, dispatch)
            }

            const computedActions = {
              ...connectedFormACs,
              ...boundArrayACs,
              blur: boundBlur,
              change: boundChange,
              array: connectedArrayACs,
              focus: boundFocus,
              dispatch
            }

and since we're here, for focus was there a reason why it was not exposed ?

@Philipp91
Copy link

Would be nice if "change" was indeed a bound action creator as the documentation says.

@dtipson
Copy link

dtipson commented Dec 18, 2016

Yep, focus appears to be missing in the actionsCreators passed to the form props.

@gustavohenke
Copy link
Collaborator

It seems like this was fixed around v6.0.4.
Tested in the examples and it worked.

@lock
Copy link

lock bot commented Jun 2, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants