从反应本机的状态 Redux Form 获取 TextInput 值
Get TextInput value from state Redux Form on react native
我有一个包含不同字段的代码。当从其他组件传递新值时,我有四个具有此值的字段,我用 this.state.
生成她的值
但是当我执行 handleSubmit() 时,此输入不会发送。一旦我已经加载它们,我已经做了一个测试更改她的值,现在是的,它们被发送了。
如何在 handlesubmit 中接收这些值?
这是部分代码:
changeImage = (values) => {
if (values.type == "profile")
this.setState({changePersonalImage: true});
else if (values.type == "featured")
this.setState({changeFeaturedImage: true});
else if (values.type == "project")
this.setState({changeProjectImage: true});
this.setState(values);
}
render() {
return (
<View>
<View>
{this.state.changePersonalImage &&
<View>
<Field name="personalImage_type" component={genericField} type="hidden" val={this.state.profile_type} />
<Field name="personalImage_fileName" component={genericField} type="hidden" val={this.state.profile_fileName} />
<Field name="personalImage_image" component={genericField} type="hidden" val={this.state.profile_image} />
<Field name="personalImage_isVertical" component={genericField} type="hidden" val={this.state.profile_isVertical} />
</View>
}
<TouchableOpacity
style={styles.btnRequest}
//onPress={this.props.handleSubmit(this.props.edit)}
onPress={this.props.handleSubmit((values) => {
console.log('valuess - handleSubmit');
console.log(values);
})}
>
<WhiteText style={styles.btnRequestText}>Save changes</WhiteText>
</TouchableOpacity>
已解决,
我在这个 post
中找到了解决方案
问题是创建隐藏字段。解决方案是调用此方法:
this.props.change('Field_name', value)
我有一个包含不同字段的代码。当从其他组件传递新值时,我有四个具有此值的字段,我用 this.state.
生成她的值但是当我执行 handleSubmit() 时,此输入不会发送。一旦我已经加载它们,我已经做了一个测试更改她的值,现在是的,它们被发送了。
如何在 handlesubmit 中接收这些值?
这是部分代码:
changeImage = (values) => {
if (values.type == "profile")
this.setState({changePersonalImage: true});
else if (values.type == "featured")
this.setState({changeFeaturedImage: true});
else if (values.type == "project")
this.setState({changeProjectImage: true});
this.setState(values);
}
render() {
return (
<View>
<View>
{this.state.changePersonalImage &&
<View>
<Field name="personalImage_type" component={genericField} type="hidden" val={this.state.profile_type} />
<Field name="personalImage_fileName" component={genericField} type="hidden" val={this.state.profile_fileName} />
<Field name="personalImage_image" component={genericField} type="hidden" val={this.state.profile_image} />
<Field name="personalImage_isVertical" component={genericField} type="hidden" val={this.state.profile_isVertical} />
</View>
}
<TouchableOpacity
style={styles.btnRequest}
//onPress={this.props.handleSubmit(this.props.edit)}
onPress={this.props.handleSubmit((values) => {
console.log('valuess - handleSubmit');
console.log(values);
})}
>
<WhiteText style={styles.btnRequestText}>Save changes</WhiteText>
</TouchableOpacity>
已解决,
我在这个 post
问题是创建隐藏字段。解决方案是调用此方法:
this.props.change('Field_name', value)