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

Ability to dynamically change time constraints

Open shank-eric opened this issue 9 years ago • 6 comments

I have a form with Start and End Time fields and I'd like to ensure that the End Time is after the Start Time, even if the user updates the Start Time. However, updating the timeConstraints during a re-render doesn't seem to change the constraints and doesn't allow me to dynamically adjust what the min hour should be. This appears to be caused by the timeConstraints being configured only during the mounting of the component and thus it does not use updates to this prop. This also seems to mostly be an issue when using the component as just a time picker because I believe switching between date and time views causes re-mounting of the TimeView and updates the constraints.

I've put together a CodePen exhibiting the issue here: http://codepen.io/anon/pen/JEoGzB.

I've also started work on a fix, but wanted to ask if I should include an option for enabling this behavior or just make it the base functionality of this option.

shank-eric avatar Jan 05 '17 15:01 shank-eric

Hi @shank-eric.

Some of the props have those limitations, unfortunately. I generally like customization, but I want to know more of how you think. So the option you're referring to would be able to enable re-rendering when changing time in TimeView mode?

simeg avatar Jan 08 '17 22:01 simeg

@simeg, it would change the TimeView component to update the timeConstraints during componentWillReceiveProps in addition to componentWillMount such that if an updated timeConstraints is passed in, it will be honored. Here's an initial pass at the change I made: https://github.com/EverFi/react-datetime/pull/1/files

shank-eric avatar Jan 11 '17 22:01 shank-eric

I ran into this myself in a very similar situation (start and end times). I ended up handling the logic in a parent component of start and end react-datetime components, but the main reason that drove me that way was that I had other factors that would have made the timeConstraint method more complicated.

Having this feature would be useful though.

layneanderson avatar Jan 12 '17 01:01 layneanderson

Hey @shank-eric @simeg @layneanderson has this feature been implemented yet? Thanks..!

manishbhatt94 avatar Dec 14 '17 11:12 manishbhatt94

Hi @manishbhatt94. No, it has not been implemented unfortunately.

simeg avatar Jan 27 '18 12:01 simeg

Are there any plans to implement something like this? Didn't see it in v3, and have some interest in it. Is there perhaps a workaround?

wschmrdr avatar Sep 23 '20 22:09 wschmrdr