首页 > 解决方案 > 在 TextInput 中粘贴值期间未触发 onChangeText

问题描述

onChangeText在 IOS 的 TextInput 中粘贴值期间不会触发。怎么可能修复它?这是我的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}));
               }
    }

标签: react-nativereact-native-iosreact-native-textinput

解决方案


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


推荐阅读