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

How to update internal phone number value when using a textComponent #144

Open
jamesl1001 opened this issue Feb 24, 2020 · 7 comments
Open

Comments

@jamesl1001
Copy link

I want to use the various methods such as isValidNumber(), getNumberType(), getValue(), getISOCode()` etc.

When I use the textComponent prop to customise the UI, how do I pass the value from this custom TextInput into the PhoneInput's state to be used by those methods?

<PhoneInput
    allowZeroAfterCountryCode={false}
    initialCountry="gb"
    // onChangePhoneNumber={test => console.log(test)}
    onSelectCountry={() => this.setState({ countryCode: this.test.getCountryCode() }) }
    onSubmitEditing={() => console.log('111')}
    ref={ref => this.test = ref}
    textComponent={() => (
        <>
            <Text>Mobile number</Text>
            <View>
                <Text onPress={() => this.test.onPressFlag()}>+{this.state.countryCode}</Text>
                <TextInput
                    keyboardType="phone-pad"
                    onChangeText={text => this.test.setState({ inputValue: text })}
                    placeholder="7123456789"
                />
            </View>
        </>
    )}
/>
@kobagapu
Copy link

kobagapu commented Mar 6, 2020

<PhoneInput
ref={ref => {
phoneno = ref;
}}
onChangePhoneNumber ={(num)=>{
setPhone(num)
}}
style={{marginLeft:"20%"}}
initialCountry = 'us'
textProps={{
placeholder:I18n.t('phone'),
returnKeyType: 'done',
keyboardType: 'phone-pad',
style:(styles.input)
}}
/>

This works

@jamesl1001
Copy link
Author

That's because you are not using the textComponent prop.

@raethlein
Copy link

raethlein commented Mar 29, 2020

Hey, based on this line , some probs such as the change listener are passed to the component, so instead of using your own onChangeText, you could try to pass the probs to the underlying element like:

textComponent={(props) => (
        <>
            <Text>Mobile number</Text>
            <View>
                <Text onPress={() => this.test.onPressFlag()}>+{this.state.countryCode}</Text>
                <TextInput
                    keyboardType="phone-pad"
                    // onChangeText={text => this.test.setState({ inputValue: text })}
                    placeholder="7123456789"
                    {...props}
                />
            </View>
        </>
    )}

@OsamaMukhtar
Copy link

I am having the same problem

@marlene89
Copy link

same issue. any one find an answer?

@NataD
Copy link

NataD commented Nov 18, 2020

Any updates on the issue? I even cannot get the value from the phone input using onChangePhoneNumber once I am using custom textComponent

@kovetskiy
Copy link

I had the same issue but then I figured out that I was using textComponent like that:

textComponent={() => ( <MyInput /> )

while I actually had to pass props:

textComponent={(props) => ( <MyInput {...props} /> )

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

7 participants