react-datetime icon indicating copy to clipboard operation
react-datetime copied to clipboard

Disable manually typing in date/time

Open tylerzika opened this issue 9 years ago • 17 comments

[ ] Bug report [x] Feature request [x] Support request

I'd like it to be: when the user inputs the date/time, they can only make changes by using the pop out calendar/clock. Allowing them to type it in manually is prone to errors.

tylerzika avatar May 26 '17 20:05 tylerzika

isn't this what the input option is for? just set it to false.

rikkit avatar May 26 '17 23:05 rikkit

@rikkit, that's is not what input currently does. When I set it to false, it completely hides the input field.

Setting input to false.

screen shot 2017-05-27 at 3 26 09 pm

Setting input to true.

screen shot 2017-05-27 at 3 27 24 pm

tylerzika avatar May 27 '17 22:05 tylerzika

Whether to show an input field to edit the date manually.

Sorry, I guess I interpreted it wrong, I thought the option referred to the text input field i.e. html input element.

Would CSS work for you?

.rdt input {
  display: none;
}

rikkit avatar May 29 '17 01:05 rikkit

@tylerzika wouldn't readOnly input prop solve your problem or am I missing some use case?

AtomicAlienZ avatar May 30 '17 10:05 AtomicAlienZ

@tylerzika check this issue and see if it helps.

jpmoyn avatar Jun 15 '17 17:06 jpmoyn

@AtomicAlienZ see below.

@jpmoyn this is what my component looks like

<ReactDateTime
   onChange={sendDateTime => this.updateSurveySentRecord({target: {name: "SEO__Survey_Sent__c", value: sendDateTime}})}
   className="slds-datepicker"
   closeOnSelect={true}
   value={this.state.sendDateTime}
   readOnly={true}
 />

and look what I can still do...

screen shot 2017-06-15 at 4 36 55 pm screen shot 2017-06-15 at 4 37 02 pm 😕

tylerzika avatar Jun 15 '17 23:06 tylerzika

@tylerzika if you followed the link i sent you should have seen that the syntax for the specific input props is inputProps={{readOnly: true}}, not just readOnly={true}. That will fix your problem.

jpmoyn avatar Jun 16 '17 13:06 jpmoyn

@jpmoyn thanks, sorry I didn't look at it right, I thought inputProps was a variable... Works perfectly!

tylerzika avatar Jun 16 '17 15:06 tylerzika

you can add in your input this attribut onkeydown="return false"

mouradmamassi avatar Nov 07 '17 09:11 mouradmamassi

@mouradmamassi I can't make it work, can you show me some code?

otelom avatar Feb 11 '18 22:02 otelom

@otelom Yes off course this is my code //HTML <input type="text" id="datefin_search" onkeydown="return false"> //JS var mycalanderfin = new dhtmlXCalendarObject(["datefin_search"]);

mouradmamassi avatar Feb 12 '18 22:02 mouradmamassi

@mouradmamassi I'm using this code and I do not understand how exactly should I apply your code suggestion in react js.

otelom avatar Feb 14 '18 13:02 otelom

@mouradmamassi, I'm using react-datetime for ReactJS

Com os melhores cumprimentos, Otelo Magalhães

2018-02-14 15:23 GMT+00:00 Mourad MAMASSI [email protected]:

@otelom https://github.com/otelom Are you using datepicker for reactJS ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/YouCanBookMe/react-datetime/issues/339#issuecomment-365640767, or mute the thread https://github.com/notifications/unsubscribe-auth/AMMknt_buoHtekc7WGd8cbWV5jAEarmaks5tUvqKgaJpZM4NoDSW .

otelom avatar Feb 14 '18 15:02 otelom

@otelom I hope this method can do the job for you ;) https://codepen.io/anon/pen/jZGEXX?editors=1111

mouradmamassi avatar Feb 14 '18 16:02 mouradmamassi

@mouradmamassi Thanks, that did the job. But I'm using ES6 so it was a little bit different but after I adapted it worked. Thanks again ;)

otelom avatar Feb 16 '18 02:02 otelom

@otelom you're welcome

mouradmamassi avatar Feb 16 '18 07:02 mouradmamassi

If you want to want it to remain clickable/editable but just disable input via keyboard you can try React: <input type="date" onKeyDown={(e) => e.preventDefault()} .... />

HTML:

adish1997 avatar Jan 14 '20 07:01 adish1997