Skip to content

[Datepicker] Add a check to fetch current system date#3656

Merged
oliviertassinari merged 1 commit intomui:masterfrom
tintin1343:datepicker-time-issue
Mar 12, 2016
Merged

[Datepicker] Add a check to fetch current system date#3656
oliviertassinari merged 1 commit intomui:masterfrom
tintin1343:datepicker-time-issue

Conversation

@tintin1343
Copy link
Copy Markdown
Contributor

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

The current issue #3545 deals with the date picker not picking up the updated system date when the dialog opens. This happens because if the system date updates but the page is not refreshed then the date which the dialog box gets is the old system date as the system date is set in the getinitialState() of the date picker and is not updated on the system date change.

I observed that there is no check when the openDialog() to get the updated date, which is what I added. I check if the Datepicker has a pre-existing selected date , if it does show that date on openDialog() else if the Datepicker is empty pick up the current system date (this will always pick up the updated date) and hence solves the problem.

Heres the example:
datepicker

Fixes #3545.

@tintin1343 tintin1343 force-pushed the datepicker-time-issue branch from ed159c2 to 6d8a952 Compare March 10, 2016 17:54
}, this.refs.dialogWindow.show);
} else {
this.setState({
dialogDate: new Date(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have this, do we still need new Date() in getInitialState() ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathanmarks : good point. I think we can remove it. Let me do the changes and check

@nathanmarks
Copy link
Copy Markdown
Contributor

@tintin1343 I think we can remove that date construction in getInitialState() now.

@tintin1343 tintin1343 force-pushed the datepicker-time-issue branch from 6d8a952 to d7292a0 Compare March 10, 2016 21:29
@tintin1343
Copy link
Copy Markdown
Contributor Author

@nathanmarks : Done. The date attribute is not needed in the getInitialState() method

@mbrookes mbrookes added the type: bug It doesn't behave as expected. label Mar 10, 2016
Comment thread src/date-picker/date-picker.jsx Outdated
getInitialState() {
return {
date: this._isControlled() ? this._getControlledDate() : this.props.defaultDate,
dialogDate: new Date(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tintin1343 You removed the wrong state item 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U wanted me to remove the dialogDate? But even removing the earlier statement didn't make.any difference.

@tintin1343 tintin1343 force-pushed the datepicker-time-issue branch from d7292a0 to 5847f99 Compare March 11, 2016 03:51
@tintin1343
Copy link
Copy Markdown
Contributor Author

@nathanmarks : Made the necessary changes. 😅

Added a check which helps pick the current system date when the date-picker dialog
 is opened.

Resolves mui#3545
@mbrookes
Copy link
Copy Markdown
Member

LGTM

oliviertassinari added a commit that referenced this pull request Mar 12, 2016
[Datepicker] Add a check to fetch current system date
@oliviertassinari oliviertassinari merged commit 092f798 into mui:master Mar 12, 2016
@oliviertassinari
Copy link
Copy Markdown
Member

@tintin1343 Thanks!

@tintin1343
Copy link
Copy Markdown
Contributor Author

@oliviertassinari : Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants