Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset initial value in redux form

I'm using redux-form. I'm showing initial values in input fields from the state. When I click on reset, the input field is still showing initial values.

How can I reset the input field?

This is my code :

const mapStateToProps = (state) => {     return {         initialValues: {             name:state.userInfo.data.name,             email:state.userInfo.data.email,             phone:state.userInfo.data.phone,             city:state.userInfo.data.city.name,         }     }; } 

This is how I'm calling initial value in the input field.

const renderField = ({ input, label, type, meta: { touched, error } }) => (     <div>         <input className="form-control control_new" {...input} placeholder={label} type={type}/>     {touched && ((error && <span>{error}</span>))}     </div> )  <Field type="text" {...name} name="name" component={renderField} label="Enter Your Name" /> 

Thanks

like image 692
Sunil tc Avatar asked Mar 10 '17 06:03

Sunil tc


People also ask

How do I change initial value in Redux?

To populate your form with initial values, you'll need to pass data to your form from your store. To do this, in your mapStateToProps() function, create a key called initialValues that is set to an object that contains the keys and values of the data you'd like to place in your form.

How do you reset redux?

props. reset() , which already knows your form name, from inside your decorated form component. You can see it in action on the "Clear Values" button in the Simple Example.

What is pristine in Redux form?

pristine means that no fields in the form have been modified yet. Perhaps you won't be able to find an exact definition of it in docs, but there is a similar terminology in Angular. You can find some details here or here. submitting , as the name suggests, means that the form is in process of submitting.


1 Answers

import {reset} from 'redux-form';  ...  dispatch(reset('myForm'));  // requires form name 
like image 59
Harsha W Avatar answered Sep 20 '22 09:09

Harsha W