Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypError: undefined is not an object (evaluating 'this.countryPicker.openModal') #138

Open
meliodev opened this issue Jan 23, 2020 · 3 comments

Comments

@meliodev
Copy link

When I invoke onPressFlag(){ this.countryPicker.openModal() } by pressing the country flag, I get undefined. Here is the code below:

`import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';

import PhoneInput from 'react-native-phone-input';
import CountryPicker from 'react-native-country-picker-modal';

export default class Test4 extends React.Component {
constructor() {
super();

this.onPressFlag = this.onPressFlag.bind(this);
this.selectCountry = this.selectCountry.bind(this);
this.state = {
  cca2: 'US',
};

}

componentDidMount() {
this.setState({
pickerData: this.phone.getPickerData(),
});
}

onPressFlag(){
this.countryPicker.openModal()
}

selectCountry(country){
this.phone.selectCountry(country.cca2.toLowerCase())
this.setState({cca2: country.cca2})
}

render(){
return(

<PhoneInput
ref={(ref) => { this.phone = ref; }}
onPressFlag={this.onPressFlag}
/>

        <CountryPicker
            ref={(ref) => { this.countryPicker = ref; }}
            onChange={(value)=> this.selectCountry(value)}
            translation='eng'
            cca2={this.state.cca2}
        >
            <View></View>
        </CountryPicker>
    </View>
)

}
}

let styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
padding: 20,
paddingTop: 60,
},
});`

@saidhappy010
Copy link

I have the same issue.
please, anyone has the solution?.
thanks.

@daviedgie
Copy link

Please refer to this my friend.
xcarpentier/react-native-country-picker-modal#270 (comment)

@sargamverma
Copy link

I have the same issue.
I am using this with expo application .
Please anyone help.
Its urgent.

Thanks in andvance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants