thegamenicorus / react-native-phone-input

Phone input box for React Native
https://www.npmjs.com/package/react-native-phone-input
MIT License
394 stars 447 forks source link

Cannot use the PhoneInput functions #106

Open paolash99 opened 5 years ago

paolash99 commented 5 years ago

Hello, I am trying to adjust the maximum length of the PhoneInput according to the country of choice. However, I cannot get the ISOCode. When I use the getISOCode() method I get an error: TypeError: undefined is not an object (evaluating 'this.phone.getISOCode'). Here is my code: /**

import React, {Component} from 'react'; import { StyleSheet, View, Button} from 'react-native'; import PhoneInput from 'react-native-phone-input';

export default class App extends Component {

getMaxLenght=()=>{ this.setState({code:this.phone.getISOCode()}) if (this.state.code==='lb'){ return 14; } if(this.state.code==='us'){ return 15; } if(this.state.code==='ca'){ return 15; } if (this.state.code==='gr'){ return 16; } }

render() { return (

{ this.phone = ref; }} style={styles.phoneStyle} textStyle={styles.numberStyle} countriesList={require('./countries.json')} initialCountry='lb' autoFormat='true' flagStyle={styles.flagStyle} textProps={{placeholder: "Enter Phone Number", keyboardType:"number-pad", maxLength:this.getMaxLenght()}} />
);

} }

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, flagStyle:{ width: 40, height: 30, borderWidth:0 },

numberStyle:{ fontSize: 20,

},

phoneStyle:{ marginHorizontal:60 } });

I tried using the other PhoneInput functions, I get the same result. Any ideas?