【发布时间】:2018-03-23 22:54:27
【问题描述】:
当上述两个文本字段均未填充时,将调用按钮的 onPress 函数。否则,我按下按钮,没有任何反应。我尝试将onPress 更改为onPress={this.handleSubmit()},但是在TextInput 中的任何数据之前调用该函数并引发错误。我也尝试过使用 tcomb-form-native 包,但问题仍然存在。在填充文本输入时,我需要更改什么才能调用 handleSubmit 函数?
handleSubmit = () => {
console.log('handle submit')
}
render() {
return (
<View style={styles.container}>
<TextInput
style={{height: 40}}
placeholder="Your name"
onChangeText={userName => this.setState({userName})}
/>
<TextInput
style={{height: 40}}
placeholder="other name"
onChangeText={otherName => this.setState({otherName})}
/>
<Button
title="Name"
onPress={this.handleSubmit}
/>
</View>
);
}
【问题讨论】:
标签: react-native