reactjs - 如何删除 React 电话号码输入中的国际选项?
问题描述
如何从react-phone-number-input
包中的选择选项中删除国际选项?我试图将这些国家/地区限制在六个。我已经添加了defaultCountry
andcountries
属性,但它仍然允许输入其他国家的电话号码。这是我的使用方法:
<PhoneInput
placeholder={placeholder}
name={name}
value={value}
onChange={onValueChange}
onBlur={handleInputBlur}
onFocus={handleInputFocus}
defaultCountry={country}
countries={["NG", "MG", "SC", "KM", "BW", "MR"]}
/>
以下是它在没有在 props 中指定的情况下包含的国际选项的显示方式:
如何删除国际选项。
解决方案
将国际道具设置为 false,以便将其删除。
通过文档 if country is US and international property is not passed then the phone number can only be input in the "national" format for US ((213) 373-4253). But if country is "US" and international property is true then the phone number can only be input in the "international" format for US (213 373 4253) without the "country calling code" part (+1)
你的代码应该是
<PhoneInput
placeholder={placeholder}
name={name}
value={value}
international = {false}
onChange={onValueChange}
onBlur={handleInputBlur}
onFocus={handleInputFocus}
defaultCountry={country}
countries={["NG", "MG", "SC", "KM", "BW", "MR"]}
/>
推荐阅读
- python - 如何从python中的数组中找到最小值和最大值?
- flutter - 如何在飞镖逻辑中获取每周日期列表
- python - 如何从 Python 数据框中提取和分离随机元组值?
- python - 如何在 wordnet 中使用超/下义词找到单词的抽象性?
- sql - 不使用窗口函数计算列
- javascript - 我需要将输入的所有数据汇总到一个变量中
- vue.js - Vuex mapState 返回对象而不是数组?
- corda - 从没有 Schema 的 Corda Vault 获取特定记录的最佳方法?
- c# - 无法将类型(公共活动实例)转换为 Xamarin Android C# 中的活动
- r - 每组不能绘制超过一个箱线图。你忘了 aes(group = ...) 吗?