antd-mobile InputItem type=phone的疑问

browser / google chrome / antd-mobile: 1.0.3

code:

<InputItem
     {...getFieldProps('phone',
      {
        initialValue: item.consigneePhone,
        rules: [
          {required: true, message: '请输入手机号码'},
        ],
      })}
    error={!!getFieldError('phone')}
    onErrorClick={() => {
      Toast.fail(getFieldError('phone'), 1);
    }}
    type="phone"
    placeholder="请输入手机号码">
    手机号码
</InputItem>

疑问:

  1. 设置 value = '18612341234' 后, 无法进行输入操作

  2. 设置 defaultValue = '18612341234' 无效, 并且提示警告

    `Warning: InputItem contains an input of type tel with both value and defaultValue props. Input elements must be either controlled or uncontrolled (specify either the value prop, or the defaultValue prop, but not both). Decide between using a controlled or uncontrolled input element and remove one of these props. More info: https://fb.me/react-controlled-components`
  3. 通过getFieldProps 设置initialValue , value正常, 但是格式需要手动处理

期望结果

设置 value 正常, 可以进行编辑. 并且有格式, eg. 186 1234 1234

阅读 5.2k
1 个回答

报告 bug 上 github 提 issue,仔细阅读issue模板,提供能复现的在线demo最佳

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进