arqex / react-datetime

A lightweight but complete datetime picker react component.
2k stars 869 forks source link

Disable manually typing in date/time #339

Closed tylerzika closed 7 years ago

tylerzika commented 7 years ago

[ ] 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.

rikkit commented 7 years ago

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

tylerzika commented 7 years ago

@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
rikkit commented 7 years ago

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;
}
AtomicAlienZ commented 7 years ago

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

jpmoyn commented 7 years ago

@tylerzika check this issue and see if it helps.

tylerzika commented 7 years ago

@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 😕

jpmoyn commented 7 years ago

@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.

tylerzika commented 7 years ago

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

mouradmamassi commented 7 years ago

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

otelom commented 6 years ago

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

mouradmamassi commented 6 years ago

@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"]);

otelom commented 6 years ago

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

otelom commented 6 years ago

@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 notifications@github.com:

@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 .

mouradmamassi commented 6 years ago

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

otelom commented 6 years ago

@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 ;)

mouradmamassi commented 6 years ago

@otelom you're welcome

adish1997 commented 4 years ago

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: