Reputation: 559
I'm using isDirty
to check if form values have entered (and disable other things based on that).
import { isDirty } from 'redux-form';
const mapStateToProps = state => ({
isFormDirty: isDirty('myform')(state)
});
This works great as in the buttons I want to disable get disabled when a form value is changed. They also get enabled when I dispatch the reset
redux-form action creator.
However, succesfully submitting the form does not clear dirty state. The buttons I have disabled by the isDirty
check remain disabled.
Do I need to manually tell redux-form that the form is now pristine? And how to do that?
Upvotes: 3
Views: 2391
Reputation: 559
I now worked around this by dispatching the initialize
action from my action creator that is passed as onSubmit
to the form.
import { getFormInitialValues, initialize } from 'redux-form';
export function saveData(data) {
return (dispatch, getState) => { // this is redux-thunk
api.saveSomething(data).then(newData => {
// dispatch some actions
dispatch(someAction(newData));
let activeFormValues = getFormInitialValues('myform')(getState());
if (activeFormValues.id === data.id) { // Reset the form with new initialValues
dispatch(initialize('myform', newData, false, { keepSubmitSucceeded: true }));
}
});
};
}
Upvotes: 1