【发布时间】:2018-08-08 06:15:37
【问题描述】:
我正在开发一个带有本机反应的应用程序。我有如下三个 TextInput 框:
如果用户插入数字,我需要自动更改 TextInput 框的焦点。然后,一旦他/她插入最后一个数字,就应该执行一个函数。
这是我的代码:
<View style={styles.squareContainer}>
<View style={styles.square}>
<TextInput
onChangeText={(oldPassword) => this.setState({oldPassword})}
style={{flex:1}}
ref="1"
keyboardType={'numeric'}
style={styles.inputText}
maxLength = {1}
underlineColorAndroid='rgba(0,0,0,0)'
numberOfLines={1}
secureTextEntry={true}
onSubmitEditing={() => this.focusNextField('2')}
/>
</View>
<View style={styles.square}>
<TextInput
style={{flex:1}}
ref="2"
onChangeText={(oldPassword) => this.setState({oldPassword})}
keyboardType={'numeric'}
maxLength = {1}
style={styles.inputText}
underlineColorAndroid='rgba(0,0,0,0)'
numberOfLines={1}
secureTextEntry={true}
onSubmitEditing={this.maxLength?1:() => this.focusNextField('3')}
/>
</View>
<View style={styles.square}>
<TextInput
style={{flex:1}}
ref="3"
onChangeText={(oldPassword) => this.setState({oldPassword})}
returnKeyType='next'
keyboardType={'numeric'}
style={styles.inputText}
underlineColorAndroid='rgba(0,0,0,0)'
numberOfLines={1}
secureTextEntry={true}
/>
</View>
</View>
换句话说,例如如果用户想要插入 153,他/她应该在第一个 TextInput 中插入 1,然后光标和焦点应该自动替换到下一个 TextInput,她/他可以插入 5,最后通过将焦点和光标移动到第三个TextInput,他/她可以插入3。一旦他插入3,我需要执行this.triggerFunction()。
如您所见,我尝试使用以下技巧,但没有成功:
onSubmitEditing={this.maxLength?1:() => this.focusNextField('3')}
你能帮我解决这个问题吗?提前致谢。
【问题讨论】:
标签: reactjs react-native textinput