-
Notifications
You must be signed in to change notification settings - Fork 868
if isValidDate is passed we need to verify if the view date is valid … #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…before trying to render the component.
Hi @JesseChrestler , I'm probably going to remove this on the next update. There is a problem with the code. If your isValidDate function doesn't allow dates in the future adding 1 day in the while loop will cause it to loop until it crashes. Can you think of any alternatives? |
Ok, let me see what i can come up with. |
Hey @JesseChrestler, thanks for your contribution. Too bad it's not working as intended. This sort of logic is sensitive, the component has complex internal state that needs consideration always. Having tests for changes like these are crucial, in my opinion. @layneanderson Let's not deploy new version with this change, if it doesn't work. If we want to deploy we can always revert this commit first. EDIT: Oh, I just realised it's already merged. |
So I have been thinking of an alternative and I might have a way. This would eliminate the while loop and make it much faster. The downside is allowing another from props parameter. This parameter would let me set the date in which the calendar would render on the initial load. This different than setting the value as I want to have the calendar render any month given this parameter. This would work for both future and past dates. Example renderDate={moment().add('1' 'M')} Will render the calendar one month in the future. This will satisfy my scenario as I would pass it my initial range of my IsValidDate function. Let me know what you think of this strategy, I think it could have a lot uses outside of my specific case. |
Also the name of the parameter needs to make sense. The other parameters like renderDay and renderMonth have different intentions and might make the API confusing. Maybe calling the parameter initialRenderDate might make it more clear. |
I ran next code on my side and it is not working and browser freezes:
the package version is: "react-datetime": "^2.10.2", |
I've removed this code in v2.10.3 because it was causing crashes. Is there an original issue that we should reopen? I believe it would be good to check isValidDate before render, just not sure best way to implement that will satisfy all edge cases. Thinking about this problem I think in a lot of cases it could be handled in the code using react-datetime (i.e. set value appropriately). |
…feature-render-input * 'master' of github.com:YouCanBookMe/react-datetime: (24 commits) Twotenthree (arqex#434) Version 2.10.2 Fix URL for 'uncontrolled elements' Fix formatting in demo README Create proper demo application Move @types/react back to devDependencies Fix build files (arqex#411) Bump to v2.10.0 (arqex#410) if isValidDate is passed we need to verify if the view date is valid … (arqex#296) Add create-react-class dependency Use same tab indentiation in all JS files Enforce tab indentation Add TODO regarding complex ternary expression Use consistent indentation in README examples Add yarn installation instructions to README Add snapshot testing Version 2.9.0 Add TS definitions for onViewModeChange callback Add callback on view mode changes Update indentation and style for consistency ...
arqex#296) * if isValidDate is passed we need to verify if the view date is valid before trying to render the component.
@andreoman Check the |
@simeg Did you read my comment before ? I wrote that isValidDate does not work in my case. |
@andreoman |
…before trying to render the component.
The calendar should only show a date that is selectable (based on isValidDate function)
Description
added some code to check isValidDate to change the viewDate to a date that can actually be selected.
Motivation and Context
My users were complaining that when there was a range that was disabled on the current month they would have to skip to the month where dates are selectable. This will now do this automatically.
Checklist