Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to disable typing/pasting into the date input and only allowing users to select from the date picker in 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.

like image 538
Afaq Ahmed Khan Avatar asked Oct 19 '25 04:10

Afaq Ahmed Khan


2 Answers

please try with below prop

inputReadOnly={true}
like image 52
Sudhakar Avatar answered Oct 21 '25 17:10

Sudhakar


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

antd-datepicker

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>
    );
  }
like image 25
blueseal Avatar answered Oct 21 '25 18:10

blueseal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!