有没有一种方法可以禁止在日期输入中键入/粘贴内容,而仅允许用户从AntD中的日期选择器中进行选择? [英] Is there a way to disable typing/pasting into the date input and only allowing users to select from the date picker in AntD?

查看:381
本文介绍了有没有一种方法可以禁止在日期输入中键入/粘贴内容,而仅允许用户从AntD中的日期选择器中进行选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以禁止在日期输入中键入/粘贴内容,而仅允许用户从AntD中的日期选择器中进行选择?禁用也不起作用.我已经遍历了文档我尝试过的方法

Is there a way to disable typing/pasting into the date input and only allowing users to select from the date picker in AntD? disabling doesn't work either. I've gone through the documentation I tried this way

import { DatePicker } from 'antd';

...

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

...

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

通过这种方式,它甚至停止通过选择器面板获取输入值.

This way it just stopped taking input values even through picker panel.

推荐答案

对于日期日期选择器,您需要在ant-calendar-input-wrap类中设置dispaly: none.

For antd date picker, you need to set dispaly: none in ant-calendar-input-wrap class.

styles.css . (您只需要在.css文件中添加此CSS)

styles.css. (You just only need to add this css in your .css file)

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

App.js

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

这篇关于有没有一种方法可以禁止在日期输入中键入/粘贴内容,而仅允许用户从AntD中的日期选择器中进行选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆