skratchdot / react-bootstrap-daterangepicker

A date/time picker for react (using bootstrap). This is a react wrapper around the bootstrap-daterangepicker project.
http://projects.skratchdot.com/react-bootstrap-daterangepicker/
Other
474 stars 203 forks source link

setOptionsFromProps creates wrong param order #82

Closed K-Leon closed 4 years ago

K-Leon commented 8 years ago

I just noticed a really problematic part in setOptionsFromProps. The function assumes that Object.keys delivers a specific order - it won't deliver this order reliable.

This results in issues if startDate is set after endDate. ( endDate get's reset )

https://github.com/skratchdot/react-bootstrap-daterangepicker/blob/eedc6c52370d53da6d0b885e4d6410989eec9aa5/lib/index.js#L47

If there's interest i'll send a bugfix ( moving endDate out of loop for now ).

y3wegy commented 6 years ago

i am same issue , this component can't set end date from parent ,end date will reset to TODAY . i found the root cause is props order : end date before start date. So how to fix? custom code ?

skratchdot commented 6 years ago

Thank you @y3wegy / @K-Leon - Seems like we need custom sort() here, so that start date happens before end date: https://github.com/skratchdot/react-bootstrap-daterangepicker/blob/eedc6c52370d53da6d0b885e4d6410989eec9aa5/lib/index.js#L44

I might be able to look into this after work today, but PR's are welcomed. Now that this repo has unit tests (and storybook), we should add a simple reproducible test case, then we can fix it (and make sure it doesn't happen again).

skratchdot commented 6 years ago

It looks like @adewitt76 submitted a fix for this in #139 , but I never saw that. Someone can try to submit a similar PR.

skratchdot commented 4 years ago

closing this due to inactivity. please re-open if this is still an issue in v6.0.0 or greater