Redux-form - Set value for a field through code?

I am creating a custom component for my form.

What I want: after I clicked a specific place in my onClick handler, I can set the appropriate value for the form field.

How to do it?

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 that it’s a kind of hack.

The best solution?

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

+7
reactjs redux
source share
2 answers

The problem is resolved. It turns out I have to make my component compatible with Redux-Form, link: http://erikras.imtqy.com/redux-form/#/faq/custom-component?_k=qnjmi9

+3
source share

Reduction Form 6

Props is used inside the form component

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

Outside a form component using Action Creators

 import { change } from 'redux-form' dispatch(change('form_name', 'field_name', 'value')) 
+4
source share

All Articles