Ad

Input, Unable To Retrieve Input Value React Native

- 1 answer

 Login(){
    alert(this.state.username);
    this.props.navigator.push({
        component: MainActivity
    })
    }



render() {
    return<View style={styles.loginView}>
        <Image style={styles.image} source={require('./Ionic.png')}/>
        <Text style={styles.loginText}>Chat System</Text>
        <TextInput style={styles.usernameText} placeholder="username" placeholderTextColor="black" onChangeText={(text) => this.setState({username: text})} />
        <TextInput style={styles.passwordText} placeholder="password" placeholderTextColor="black" onChangeText={(text) => this.setState({password: text})}  onSubmitEditing={this.Login} secureTextEntry/>
        <TouchableWithoutFeedback onPress={this.Login}><View style={styles.loginButton}> <Text style={styles.loginButtonText}>Sign In</Text></View></TouchableWithoutFeedback>
        <TouchableWithoutFeedback><View style={styles.signUpButton}><Text style={styles.signUpButtonText}>Sign Up</Text></View></TouchableWithoutFeedback>
        <TouchableWithoutFeedback><View><Text style={styles.forgetPasswordText}>Forgot password?</Text></View></TouchableWithoutFeedback>
    </View>

}

I need to get value of the username and password input, in the login method, when clicked on Log-In or pressing enter after entering password.

I am currently gettingthis error while running in iOS

Ad

Answer

I tried your code and apparently a white-space over there:

<TouchableWithoutFeedback onPress={this.Login}><View style={styles.loginButton}> <Text style={styles.loginButtonText}>Sign In</Text></View></TouchableWithoutFeedback>

causes the error.

Ad
source: stackoverflow.com
Ad