7

I'm creating a customised component for my form.

What I want: after I click a certain location, in my onClick handler, I can set the corresponding value for the form field.

How to do that?

My current solution:

_onClick(value, evt) {
  const {field, dispatch} = this.props
  if(dispatch){
    dispatch({type: "redux-form/CHANGE", field: field.name, value: value, touch: false, form: field.form})
  }
}

it doesn't work yet.. but even if it works, I feel this is kind of hack.

Any better solution?

Note: I also asked this question on the issue page for redux-form: https://github.com/erikras/redux-form/issues/369

3
  • I'm voting to close this question because it is resolved Commented Dec 14, 2015 at 15:51
  • I'm voting to close this question as off-topic because it has been resolved. Commented Jan 28, 2016 at 18:08
  • You should tag a question as off-topic because it has been resolved. That's not how off-topic is supposed to be used. This shouldn't be closed. Commented Feb 16, 2017 at 17:10

2 Answers 2

15

Redux Form 6

Inside the form component using props

this.props.change('field_name', 'value')

Outside the form component using Action Creators

import { change } from 'redux-form'

dispatch(change('form_name', 'field_name', 'value'))
Sign up to request clarification or add additional context in comments.

Comments

2

Issue resolved. It turns out that I should make my component compatible with Redux-Form, reference: http://erikras.github.io/redux-form/#/faq/custom-component?_k=qnjmi9

3 Comments

I would suggest closing this issue if it's resolved.
@jpierson I'm getting an upvote and my close request didn't vent through. I think for the purpose of reference for future developers, I'll just keep the question. (yes, and I'm aware that there's a delete button)
Just fyi, link now hits a 404.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.