onChangeText
。如何解决?
这是我的TextInput
:
<TextInput
value={this.state.username}
style={styles.input}
placeholder='Email'
placeholderTextColor='#9D9D9D'
returnKeyType='next'
selectTextOnFocus={true}
onSubmitEditing={() => this.passwordRef.focus()}
autoCapitalize='none'
autoCorrect={false}
autoComplete='email'
keyboardType='email-address'
onChangeText={ text => this.onChangeEmail('username', text) }
/>
onChangeEmail = async (key, value) => {
await this.setState({ [key]: value })
const { username } = this.state
if (username.trim() === "") {
this.setState(() => ({ emailError: "Required"}));
return
}
else if (!username.match(/.+@.+/) ){
this.setState(() => ({ emailError: "Not an email address"}));
return
}
else {
this.setState(() => ({ emailError: null}));
}
}
答案 0 :(得分:0)
我找到了解决此问题的方法,而不是onChangeText
,而是使用onChange
,之后TextInput
开始按预期工作。