I am trying to access fields data in action computing theirs values into summary.
RequestForm = reduxForm({
form: 'TrainingRequestForm',
fields: [
'section1.name',
'section1.costs.overall',
'section1.costs.food',
'section1.costs.other',
],
},
(state, props) => {
return {
app: state.app
}
},
(dispatch, props) => {
return {
onSubmit: (formData) => {
dispatch({
type: 'FORM_UPDATED_WITH_DATA',
form: formData
})
},
onCostsUpdate: (fields) => {
let _summary = 0;
_.map(fields.section1.costs, (cost) => {
let value = parseFloat(cost.value);
console.log("MAP VALUE", value);
_summary += ( ! isNaN(value)) ? value : 0;
});
dispatch({
type: 'COSTS_UPDATED',
summary: _summary
})
}
}
})(RequestForm);
I've tried to bind fields to the action creator
class RequestForm extends Component {
constructor(props) {
super(props);
this.onCostsUpdate = props.onCostsUpdate.bind(null, props.fields);
// this.state = {};
this.onCostsUpdate();
}
...
...
}
Is there any realiable way to access fields values in action creator?
If you used thunk middleware, you could then use getValues()
. That should do it.
Thanks.
costsUpdate: () => {
dispatch((dispatch, getState) => {
let _summary = 0;
_.map(getState().form.TrainingRequestForm.section1.costs, (cost) => {
let value = parseFloat(cost.value);
console.log("MAP VALUE", value);
_summary += ( ! isNaN(value)) ? value : 0;
});
dispatch({
type: 'COSTS_UPDATED',
summary: _summary
})
});
},
works fine!
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.
Most helpful comment
If you used thunk middleware, you could then use
getValues()
. That should do it.