I have a save button binded to the dirty state, when form is dirty, enable the button, otherwise disable it.
This is good for editing an item. But when I add an item, the save button is disabled by default, because dirty is false by default.
Is there a way to set the form to dirty state?
According to Action Creators documentation of redux-form, you can do it when you initialize data for your form:
import { initialize } from 'redux-form';
export const initializeForm = (formName, newData) => async (dispatch, getState) => {
await dispatch(initialize(formName, newData, false));
};
Also, you can set additional options in that function f.e
import { initialize } from 'redux-form';
export const initializeFormWithOldValues = (formName, newData) => async (dispatch, getState) => {
await dispatch(initialize(formName, newData, false, { keepSubmitSucceeded: true, keepValues: true }));
};
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