Comments (10)
@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.
You can do
<PhoneInput ref="phone" textProps={{ placeholder: "1122" }} />
for add placeholder to the input
from react-native-phone-input.
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.
hi @ikiugu did you get that hoe to use placeholder...tell me how use it
from react-native-phone-input.
Hi @ashutoshshubam unfortunately I did not get how to use this
from react-native-phone-input.
still same issue with no luck
from react-native-phone-input.
Same issue
from react-native-phone-input.
Hi @ikiugu use react-native-country-picker-modal
it has placeholder
from react-native-phone-input.
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.
@thegamenicorus Can this fix be implemented and the package updated asap?
from react-native-phone-input.
Related Issues (20)
- Add typescript support
- App crashes when trying to change country code.and when selecting country flag, country code not displaying. HOT 1
- App crashes in lenovo vibe k4 note
- Is this dead?! HOT 3
- How to update internal phone number value when using a textComponent HOT 7
- PhoneInput is just showing country flag but not showing country code. HOT 3
- So many warnings Bad
- onFocus not Working HOT 1
- maxlength support HOT 8
- Small improvements to the country picker (background, touch background to close) HOT 1
- [Suggestion] Use system flag instead of png
- InitialCountry is not working properly HOT 1
- Switch to @react-native-community/picker instead of the 'react-native' one
- Move to @react-native-community for management or some other collaborator HOT 3
- How to get isFocused()
- Flag is not changing with phone number HOT 6
- RNCAndroidDialogPicker
- 🆕 Feature request: Add placeholder for masked input
- Search Functionality
- Support senegalese operator promobile (+221 75)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-phone-input.