[英]How to update the state of a field programmatically using redux-form
I currently have 2 inputs which look like this: 我目前有2个输入,如下所示:
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.
例如,如果我在开始日期输入中输入了08/15/2018,我希望结束日期输入等于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 变量
startDate
从开始日期输入中捕获输入
The current code is able to display the date under end date input, however, it is not updating the redux field - it remains undefined. 当前代码能够在结束日期输入下显示日期,但是,它没有更新redux字段-仍未定义。
How can I display the data and also save it in redux form? 如何显示数据并将其保存为redux格式?
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.
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)),
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.