Reputation: 2457
I need to make dispatch and change the form data after page loaded:
dispatch(change("project", field, value));
however this will change "pristine" to false and "dirty" to true, anyone has a good solution for such case?
Upvotes: 3
Views: 6100
Reputation: 814
I don't know if it is the correct way, but it is working for me.
this.props.dispatch({type: '@@redux-form/BLUR', payload: yourPayload, meta: {form: "formName", field: "formField", touch: true}});
I dispatch the code above, at the onChange event of my field, forcing the redux-form to update the pristine status.
Upvotes: 0
Reputation: 246
You can set the silent flag to true, this will not update pristine and dirty flags.
Example: actions.change(model, value, { silent: true })
You could also use actions.load()
.
Difference between load()
and change()
This is different than calling actions.change(model, value, { silent: true }). Both are similar with one main difference: actions.load also updates the .loadedValue, whereas a silent change does not.
https://davidkpiano.github.io/react-redux-form/docs/api/actions.html#actions-load
Upvotes: -2
Reputation: 7016
In order to achieve this, you can provide initialValues
to decorated with reduxForm component:
compose(
connect((state) => ({
initialValues: state.someData
})),
reduxForm({
form: 'someForm'
})
)(Component)
Or, alternatively, you can use initialize
action creator from redux-form
after data will be loaded from server:
dispatch(initialize('myForm', newInitialValues));
Dispatching initialize
action will set state of your form to pristine
Upvotes: 4