【问题标题】:Is there a way to disable typing/pasting into the date input and only allowing users to select from the date picker in AntD?有没有办法禁止在日期输入中输入/粘贴,只允许用户从 AntD 中的日期选择器中进行选择?
【发布时间】:2020-03-10 07:01:49
【问题描述】:

有没有办法禁止在日期输入中输入/粘贴,只允许用户从 AntD 中的日期选择器中选择?禁用也不起作用。我已经通过documentation我尝试过这种方式

import { DatePicker } from 'antd';

...

handleDateChange = (e) => {
  e.preventDefault();
}

...

render() {
  ...
  <DatePicker onChange={this.handleDateChange} ... />
  ...
}

这样,即使通过选择器面板,它也会停止获取输入值。

【问题讨论】:

    标签: javascript reactjs datepicker antd


    【解决方案1】:

    对于antd date picker,需要在ant-calendar-input-wrap类中设置dispaly: none

    styles.css。 (你只需要在你的.css文件中添加这个css)

    .ant-calendar-input-wrap {
      display: none;
    }
    
    

    App.js

     render() {
        return (
          <div className="App">
            <DatePicker  />
          </div>
        );
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      相关资源
      最近更新 更多