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
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'))
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With