在TextInput中粘贴值期间不会触发onChangeText

时间:2019-05-12 20:49:27

标签: react-native react-native-ios react-native-textinput

在IOS的TextInput中粘贴值期间不会触发

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}));
               }
    }

1 个答案:

答案 0 :(得分:0)

我找到了解决此问题的方法,而不是onChangeText,而是使用onChange,之后TextInput开始按预期工作。