Reputation: 115
I currently have 2 inputs which look like this: I'm trying to update the end date input based on the first date input. Example if I input 08/15/2018 inside start date input I expect end date input to equal 08/15/2018.
My current code looks like this for end date input:
<Field
component="input"
format={(value, name) => {
if (startDate.length && name === "start_date") {
return startDate;
}
return value;
}}
name="end_date"
onChange={onDateChange}
type="date"
/>
The variable startDate
captures the input from start date input
The current code is able to display the date under end date input, however, it is not updating the redux field - it remains undefined.
How can I display the data and also save it in redux form?
Upvotes: 0
Views: 173
Reputation: 2309
import { getFormValues, change } from 'redux-form';
Fetch value of field first
const mapStateToProps = state => ({
formValues: getFormValues('<formname>')(state) || {},
});
Access that field inside above object received. formValues.
You can use change to change value in store.
change(field:String, value:any)
export const mapDispatchToProps = dispatch => ({
setDate: value => dispatch(change('<formName>', value, null)),
});
Upvotes: 1