【问题标题】:react-bootstrap-typeahead restrict input to only numbersreact-bootstrap-typeahead 将输入限制为仅数字
【发布时间】:2020-11-05 06:37:08
【问题描述】:

使用 react-bootstrap-typeahead

<Typeahead
    {...this.state}
    id="basic-example"
    onChange={id => this.setState({ id })}
    options={id}
    placeholder="Select ID"
/>

是否可以将 Typeahead 的输入限制为仅数字?如果是,请提供一个概述如何做到这一点

【问题讨论】:

    标签: reactjs react-bootstrap react-bootstrap-typeahead


    【解决方案1】:

    是的,您可以设置inputProps:

    <Typeahead
      {...this.state}
      id="basic-example"
      inputProps={{
        type: 'number',
      }}
      onChange={id => this.setState({ id })}
      options={id}
      placeholder="Select ID"
    />
    
    

    【讨论】:

    • inputProps 不起作用,控制台没有错误,我仍然可以输入字母,有什么要添加的吗?
    • @sumanth,对我来说很好用:codesandbox.io/s/dank-morning-qmj7q
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2020-12-01
    • 2013-01-14
    • 2013-08-21
    • 1970-01-01
    相关资源
    最近更新 更多