Lucky_girl
Lucky_girl

Reputation: 4863

onChangeText is not triggered during pasting value in TextInput

onChangeText is not triggered during pasting value in TextInput in IOS. How is possible to fix it? Here is my 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}));
               }
    }

Upvotes: 1

Views: 1307

Answers (1)

Lucky_girl
Lucky_girl

Reputation: 4863

I found the solution for this problem, instead of onChangeText, I used onChange, after that TextInput started work as expected.

Upvotes: 2

Related Questions