Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

fix(datepicker): format values received from external model changes #2943

Conversation

jessedhillon
Copy link

When ngModel.$render receives a value updated externally (that is, not as a response to a datepicker event, but some other model update) it does not actually apply configured formatting of any kind. It is assumed that the value is a string, but if it is an instance of Date then it is implicitly cast to a string and the element's value is set to that. This fix corrects the behavior by parsing it and applying local filters before assigning the element's value.

When `ngModel.$render` receives a value updated externally (that is, not
as a response to a datepicker event, but some other model update) it
does not actually apply configured formatting of any kind. It is assumed
that the value is a string, but if it is an instance of `Date` then it
is implicitly cast to a string and the element's value is set to that.
This fix corrects the behavior by parsing it and applying local filters
before assiging the element's value.
@chrisirhc
Copy link
Contributor

Thank you for your contribution. This PR is missing tests that verify the addition of this missing functionality.
Also, usually it would be helpful if you could also demonstrate this issue with a Plunker.

@jessedhillon
Copy link
Author

Thanks Chris. I took a cursory stab at creating a plunkr but couldn't repro the issue in that environment. It's possible I'm doing something wrong -- here's what I'm seeing:

anim

But, I could be doing something wrong because in this stripped down Plunkr it works just fine: http://plnkr.co/edit/ONQyPbP3ksitNixbagcp?p=preview

@chrisirhc
Copy link
Contributor

Are you using AngularJS 1.3 ? This looks like a 1.3 bug that has been reported before (#2659).
We're going to work on supporting it very soon, but right now it's still not supported at the moment.

@jessedhillon
Copy link
Author

Yeah that's what it was, I tried including 1.2 and it worked as expected. Would this help as a fix for that issue?

@KrisBraun
Copy link

This fixes the issue for me. Would love to see it merged.

@KrisBraun KrisBraun mentioned this pull request Dec 30, 2014
@uberspeck
Copy link
Contributor

Would love to see this merged as well!

@uberspeck
Copy link
Contributor

BTW, here's an example of the bug on jsFiddle
http://jsfiddle.net/uberspeck/4ht8y4nw/

@uberspeck
Copy link
Contributor

FWIW, @DaveWM has a workaround: #2659 (comment)

@Arkh1
Copy link

Arkh1 commented Jan 14, 2015

As a side note... if ng-minlength is added to the input field it breaks the datepicker. Anybody have any ideas on what might be the cause of that?

@spongessuck
Copy link

Why hasn't this been merged yet?

@karianna
Copy link
Contributor

@jessedhillon are you able to add a test for this PR?

@jessedhillon
Copy link
Author

Yeah, I'll try to get to it this weekend

@jessedhillon
Copy link
Author

Question: isn't this issue covered by the test at line 1316 in src/datepicker/test/datepicker.spec.js, custom format updates the input correctly when model changes?

@karianna
Copy link
Contributor

Should be yes, I assume the test still passes?

@alvinyao
Copy link

Should it be merged now?

@karianna
Copy link
Contributor

Yes - there's a Cherry Picking technique involved which I and other new maintainers are going to learn about in tonight's meeting. I'm hoping that several PR's will start to get 'merged' over the coming weeks.

@jessedhillon
Copy link
Author

Sorry for the delay in response. Yes, it's passing the test in my branch. Looks like you already figured it out though! 👍

@antoinepairet
Copy link

Should be fixed in 5f9afe5

Closing for now. Thanks to all

@karianna karianna added this to the 0.13.0 milestone Feb 21, 2015
antoinepairet pushed a commit that referenced this pull request Feb 21, 2015
Closes #3293
Closes #3279
Closes #2440
Closes #2932
Closes #3074
Closes #2943
Closes #2733

Fixes #3047
Fixes #2659
Fixes #2681
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants