Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize the redux-form with dirty set true?

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?

like image 897
cool fuq Avatar asked Dec 05 '25 14:12

cool fuq


1 Answers

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 }));
};
like image 91
Serhii Onishchenko Avatar answered Dec 10 '25 12:12

Serhii Onishchenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!