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
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.
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.
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.
import {reset} from 'redux-form'; ... dispatch(reset('myForm')); // requires form name
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