Giter Club home page Giter Club logo

Comments (10)

shimatai avatar shimatai commented on September 24, 2024 9

@emjayschoen to achieve a solution that supports a initial country code and a placeholder, you should do this:

Edit index.js of react-native-phone-input and add the following method:

componentDidMount() { if (this.props.textProps.placeholder) { this.setState({ formattedNumber: this.state.formattedNumber + ' ' + this.props.textProps.placeholder}); } }

Then you should add a onFocus on <TextComponent ... /> (line 189 of version 0.2.1):

onFocus={() => { this.setState({ formattedNumber: formattedNumber.replace(/[^0-9+-]/g, '') }); }}

PhoneInput field only allows the user to type numbers (because it uses keyboardType = "phone-pad"), so when user focus on input field, it removes all non-phone digits (0-9 +-) of placeholder.

Then all you got to do is to declare a placeholder in <PhoneInput .../>, like this:

<PhoneInput textProps={{ placeholder: 'Cellphone', placeholderTextColor: '#c0c0c0' }} initialCountry={"us"} />

The result will be:
"+1 Cellphone" (for US)
When user focus the input field, it will remain "+1" and the user types the cellphone number.

from react-native-phone-input.

thegamenicorus avatar thegamenicorus commented on September 24, 2024 2

Hi @mohamedtijani

You can do

<PhoneInput ref="phone" textProps={{ placeholder: "1122" }} />

for add placeholder to the input

from react-native-phone-input.

ikiugu avatar ikiugu commented on September 24, 2024 1

Hi @thegamenicorus I still cant add a placeholder. Even when copying the above code. It does not display.
Here is my code: <PhoneInput ref="phone" onPressFlag={this.onPressFlag} textProps={{ placeholder: '1122' }} />

from react-native-phone-input.

ashutoshshubam avatar ashutoshshubam commented on September 24, 2024

hi @ikiugu did you get that hoe to use placeholder...tell me how use it

from react-native-phone-input.

ikiugu avatar ikiugu commented on September 24, 2024

Hi @ashutoshshubam unfortunately I did not get how to use this

from react-native-phone-input.

vksgautam1 avatar vksgautam1 commented on September 24, 2024

still same issue with no luck

from react-native-phone-input.

ckOfor avatar ckOfor commented on September 24, 2024

Same issue

from react-native-phone-input.

ashutosh-patel95 avatar ashutosh-patel95 commented on September 24, 2024

Hi @ikiugu use react-native-country-picker-modal
it has placeholder

from react-native-phone-input.

emjayschoen avatar emjayschoen commented on September 24, 2024

The problem (for me at least) was actually that the default initialCountry value ('us') was setting the value of the input to "+1", so the non-empty value meant the placeholder wasn't shown. If I backspaced to delete the "+1", the placeholder appeared as I set it.

The novel solution is setting initialCountry code to null, which shows the placeholder but means users will always have to manually select a country code every time.

A better solution would allow setting both an initial country code and a placeholder. If the placeholder is set, show the placeholder instead of the flag and "+1" value, then add the flag and "+1" once the user focuses on the input for the first time.

@thegamenicorus Thoughts on whether something like this could be added?

from react-native-phone-input.

shridhar-s avatar shridhar-s commented on September 24, 2024

@thegamenicorus Can this fix be implemented and the package updated asap?

from react-native-phone-input.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.