Skip to content
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

datepicker: startAt and setting value doesn't work correctly #4358

Closed
fxck opened this issue May 2, 2017 · 11 comments
Closed

datepicker: startAt and setting value doesn't work correctly #4358

fxck opened this issue May 2, 2017 · 11 comments
Assignees

Comments

@fxck
Copy link
Contributor

fxck commented May 2, 2017

repro (using mmalerba:dp-a11y):

  • predefine value to 2017-05-02 (YYYY-MM-DD), input shows correctly 02/05/2017
  • open datepicker, it opens on a wrong month (second, instead of the fifth)
  • select 6th day of the second month (that was open), input changes to 06/02/2017 (should have been 06/05/2017)
  • close and open input again, selected day is set to second of february, but calendar opens at sixth month

@mmalerba

@fxck fxck changed the title datepicker: startAt and setting value doesn't work correcly datepicker: startAt and setting value doesn't work correctly May 2, 2017
@mmalerba mmalerba self-assigned this May 2, 2017
@mmalerba
Copy link
Contributor

mmalerba commented May 6, 2017

This is a limitation of the native JS Date object since It's not possible to set a parse format. We are planning to add a MomentDateAdapter soon (and corresponding MD_MOMENT_DATE_FORMATS) that will work with moment.js, a library that has more robust date parsing and formatting.

If you don't want to use moment, it's easy to write your own adapter for whatever date implementation you want

@fxck
Copy link
Contributor Author

fxck commented May 6, 2017

Hmm, right. I've already written my own date-fns adapter, but apparently it cannot parse different formats either... yet anyway - date-fns/date-fns#375

But doesn't this basically mean that you won't able to use locale out of the box unless you use momentjs, which is absolutely humongous untreeshakable lib? Wouldn't it be worth shipping with an adapter that can do actually this?

@mmalerba
Copy link
Contributor

mmalerba commented May 8, 2017

Happy to consider adding adapters for other implementations, but implementing robust internationalized date parsing and formatting is outside the scope of Angular Material. NativeDateAdapter is provided for users who need a very basic implementation that doesn't depend on any additional libraries, but in most cases people will want to use the moment adapter or create their own.

@mmalerba
Copy link
Contributor

Closing this since its WAI for NativeDateAdapter.

@fxck
Copy link
Contributor Author

fxck commented May 16, 2017

@mmalerba these issues will keep piling on, I think it would be worth adding some all caps bold statement to calendar docs that it doesn't support any other locale than those with MM-DD-YYYY formats.

@emreavsar
Copy link

I cannot understand how you guys from material are not providing at least one MomentDateAdapter, so that everyone can use a basic version of i18nalized date-pickers. I know there are ways to implement it, but only supporting MM-DD-YYYY out of the box is not enough.

@mmalerba
Copy link
Contributor

@emreavsar We plan to offer a Moment adapter, we have some issues to resolve with our packaging structure before we can do that. We don't want to force a Moment.js dependency on people who aren't even using the adapter

@emreavsar
Copy link

emreavsar commented May 31, 2017 via email

@mzernetsch
Copy link

Found a simple workaround that works for my use-case.
I set the startAt property to the date i provide as ngModel.
Now (using german locale) the datepicker will open at the correct month.

  <md-input-container>
    <input mdInput [mdDatepicker]="picker" placeholder="Choose a date" [(ngModel)]="date">
      <button mdSuffix [mdDatepickerToggle]="picker"></button>
    </md-input-container>
  <md-datepicker #picker [startAt]="date"></md-datepicker>

@fxck
Copy link
Contributor Author

fxck commented Jun 13, 2017

At the time of writing this startAt didn't require Date object, which was part of the problem, the other is, that after you select a day, using german locale and then close and open the calendar again, it will be on a wrong month.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants