【发布时间】:2019-12-17 06:24:49
【问题描述】:
我是 react-native 的新手。我有 3 个文本输入字段 t1, t2, t3。当达到极限时,我已经完成了对下一个输入字段的关注。现在我陷入了一种情况,不知何故,我的文本输入字段t1 和t1 已经达到了最大限制。但是当我按下另一个输入时,它并没有关注下一个输入字段t2。
<TextInput
onChangeText={text => this.setState({ v1: text })}
keyboardType='number-pad'
maxLength={1}
autoCompleteType={'off'}
autoFocus={true}
ref={ref => this.v1Ref = ref}
onChange={event => {
if (event.nativeEvent.text !== '') {
this.v2Ref.focus();
}
}}
/>
<TextInput
onChangeText={text => this.setState({ v2: text })}
keyboardType='number-pad'
maxLength={1}
autoCompleteType={'off'}
ref={ref => this.v2Ref = ref}
onChange={event => {
if (event.nativeEvent.text !== '') {
this.v3Ref.focus();
}
}}
onKeyPress={({ nativeEvent }) => {
if (nativeEvent.key === 'Backspace') {
if(this.state.v2== '')
this.v1Ref.focus(); //here it is focusing on field t1 on backspace press and then if I am trying to give another input It's not going to t2 because t1 has reached its limit.
}
}}
/>
【问题讨论】:
标签: reactjs react-native react-native-textinput