0

I have a button "addData" , which opens modal with form inside, and a grid, on which click of row opens same model (with pre-filled valus).

My problem is, after clicking on row, when i click on "addData" button the form should be reset, but it is having previous pre-filled value.

Note that i am initializing form values with props. Whereas "addData" button is in another component(does it make any difference? because my other functionalities working totally fine).

this.props.initialize({ title: data[0].title, startdate: data[0]})

Below code is not working for me,

$(document).on("click", "#addData", function (e) {
   // dispatch(reset("myformName"));
   dispatch(initialize('myformName', {}));
});

It is throwing error "dispatch is not defined". What i did wrong?

How can i reset redux form in model? Can't i reset on click event of button?

Tholle
  • 108,070
  • 19
  • 198
  • 189

1 Answers1

0

You're using dispatch as a standalone function. dispatch is a method of redux's store. You'll need to either import the store and use

store.dispatch(initialize('myformName', {}));

or better - use mapDispatchToProps and attach the action to the addData click. Using jquery with react-redux is a really bad practice and this is one of the examples why. If you have trouble connecting mapDisatchToProps with your component post your component code.

Vladimir Bogomolov
  • 1,754
  • 13
  • 17