Comments (6)
How did you end up doing it? I know onChange
will let you get the value but I would like to do it using refs
.
from react-datetime.
Hey!
I think this is an usual problem for developers starting using react, don't know if this is your case.
Input type of components are usually used in a controlled way, so we set the prop value
with some date that we store and keep track of it.
Then when the value changes, we need to update the value of our variable, and that will be given again to the datepicker. So we always have the value stored by ourselves.
See react docs: https://reactjs.org/docs/forms.html#controlled-components
In case you don't like controlled components (that you should if you are using react) you can use it in a uncontrolled way using defaultValue
and you can listen to changes using onChange
. The problem is that you won't be able to update the value programmatically that way. You are just a listener.
https://reactjs.org/docs/uncontrolled-components.html
In case you don't like any of those alternatives, you can access to the internal state of the component's instance using refs. Totally discouraged, because internals can change at any time without any advice breaking your application completely. If we don't care about it and want to use the component in a way it was never thought of, it's possible to access to the internal value using:
// in the render method
<Datetime ref={ instance => this.picker = instance }/>
// anywhere else in the component
let date = this.picker.state.selectedValue
from react-datetime.
Ignore this, I was being stupid.
from react-datetime.
Still no docs. I must be stupid too...
I don't think onChange
is the solution 'cause I also want to clear the selected value.
from react-datetime.
I kind of figured out that I had to use it in a controlled manner by searching a little more.
Still, README.md
should explain clearly that this is supposed to be used like that. There's no explanation or example anywhere about anything related to reading the value.
from react-datetime.
@arqex It's a nice plug in but It would be better if you put how to get Datetime component value when onChange and how to set initial value
from react-datetime.
Related Issues (20)
- Date time picker is working fine in local but not in cloud server once code has been moved HOT 2
- not work as a control component
- Minified React error #130 HOT 1
- Select wrong date 31/08 v3.1.1 HOT 10
- Add name attribute to react date time HOT 1
- Custom arrows
- Year range displayed in the header.
- Console spammed with Invalid date passed to the `setViewDate`
- Issue while selecting previous month date from FEBRUARY. HOT 12
- onBeforeNavigate, onNavigateForward these two props should have access to value as shown in docs
- Keyboard input for time
- webpack error HOT 1
- umd not working in browser
- disabled not working when using input props
- What is the latest version?
- When date is changed before daylight savings, time does not update to be standard time
- Date Lable duplicates in Every Year of April(Day-Light Saving) when Timezone is "Africa/Cairo"
- Soluiton
- Enable the option to edit the time in the Timepicker. HOT 1
- Not able to set the date manually
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-datetime.