【问题标题】:onChangeText is not triggered during pasting value in TextInput在 TextInput 中粘贴值期间未触发 onChangeText
【发布时间】:2019-05-12 20:49:26
【问题描述】:

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-native react-native-ios react-native-textinput


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-09
    • 2011-07-30
    • 1970-01-01
    • 2020-03-06
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    相关资源
    最近更新 更多