Skip to content

returnType config option allows return of a moment() value to ngModel #39

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

Closed
wants to merge 1 commit into from

Conversation

ilkelma
Copy link

@ilkelma ilkelma commented Jan 29, 2014

(First pull request so bear with me if I've done something wrong)

As wlingke stated in issue #30 moment is used for formatting and parsing already and thus this fits very easily within an angular app that makes use of moment for date storage. My use case is similar to his in that I need to store the ngModel value as a moment and not a date.

From a usability standpoint the way I've implemented it the default is to behave as it does now, returning a js date object. It can then be changed by passing in returnType: 'moment' to the directive's configuration.

I've included karma tests as well.

…tead of a date as desired (as well as karma tests)
@alex6o
Copy link

alex6o commented Jun 4, 2014

+1

@dalelotts
Copy link
Owner

Thanks for the PR!

Sorry I have not gotten to this one for so long.

I'm wondering if this can be implemented without a configuration option? When first opened, we can grab the typeof the model ('date', 'string', 'number', or 'moment') and just use that type to determine the return type.

Thoughts?

@rottingcorpse
Copy link

Any news on pull request? Seems to be very useful...

@dalelotts dalelotts added Waiting for response Support Question Please use Gitter or Stackoverflow for questions and removed Support Question Please use Gitter or Stackoverflow for questions labels Nov 19, 2014
@dalelotts
Copy link
Owner

I haven't really looked at this one in detail. I didn't hear back from the OP or anyone else so it's not clear that there is much of a need for this.

@ilkelma
Copy link
Author

ilkelma commented Nov 19, 2014

Apologies for the delay in responding. I ended up going with another
solution for other reasons anyway. But to the point at hand I implemented
this as a non default config option primarily because you expressed concern
about how useful this would be to the majority of users.

typeof could be used to make it more flexible but I would be concerned that
that might lead to unexpected and confusing problems if the data going in
is not of the intended type.

On Wed, Nov 19, 2014 at 02:38 Dale Lotts [email protected] wrote:

I haven't really looked at this one in detail. I didn't hear back from the
OP or anyone else so it's not clear that there is much of a need for this.


Reply to this email directly or view it on GitHub
#39 (comment)
.

@abelaska
Copy link

abelaska commented Dec 8, 2014

+1

dalelotts added a commit that referenced this pull request Nov 18, 2015
…g data in the model

Accepts any string value, but the following values have special meaning (these values are case sensitive) :
 * ```'Date'``` stores a Date instance in the model. Will accept Date, moment, milliseconds, and ISO 8601 strings as initial input from the model
 * ```'moment'``` stores a moment instance in the model. Accepts the same initial values as ```Date```
 * ```'milliseconds'``` store the epoch milliseconds (since 1-1-1970) in the model. Accepts the same initial values as ```Date```
-Any other value is considered a format string.
-When accepting values from, and saving values to the model, this directive tries to be as flexible as possible. Dates, moments, and milliseconds are all accepted as input no matter what you specify for ```modelType```. However, strings are problematic and often lose timezone information, so use caution when storing strings.
-If you must use a string, be aware that the format stored in the model must exactly match the format specified in ```modelType```. For example, the value in the model is ```'2015-12-31'``` then using ```modelType: 'MM-DD-YYYY'``` will cause an exception.
-I predict that I will regret adding this feature.

closes #241, closes #190, closes #39
dalelotts added a commit that referenced this pull request Nov 18, 2015
…g data in the model

Accepts any string value, but the following values have special meaning (these values are case sensitive) :
 * ```'Date'``` stores a Date instance in the model. Will accept Date, moment, milliseconds, and ISO 8601 strings as initial input from the model
 * ```'moment'``` stores a moment instance in the model. Accepts the same initial values as ```Date```
 * ```'milliseconds'``` store the epoch milliseconds (since 1-1-1970) in the model. Accepts the same initial values as ```Date```
-Any other value is considered a format string.
-When accepting values from, and saving values to the model, this directive tries to be as flexible as possible. Dates, moments, and milliseconds are all accepted as input no matter what you specify for ```modelType```. However, strings are problematic and often lose timezone information, so use caution when storing strings.
-If you must use a string, be aware that the format stored in the model must exactly match the format specified in ```modelType```. For example, the value in the model is ```'2015-12-31'``` then using ```modelType: 'MM-DD-YYYY'``` will cause an exception.
-I predict that I will regret adding this feature.

closes #241, closes #190, closes #39
@dalelotts
Copy link
Owner

@ilkelma good point, after doing some digging I found that it is quite frequent that the data going in
is not of the intended type.

dalelotts added a commit that referenced this pull request Nov 18, 2015
…g data in the model

Accepts any string value, but the following values have special meaning (these values are case sensitive) :
 * 'Date' stores a Date instance in the model. Will accept Date, moment, milliseconds, and ISO 8601 strings as initial input from the model
 * 'moment'stores a moment instance in the model. Accepts the same initial values as ```Date```
 * 'milliseconds' store the epoch milliseconds (since 1-1-1970) in the model. Accepts the same initial values as ```Date```
-Any other value is considered a format string.
-When accepting values from, and saving values to the model, this directive tries to be as flexible as possible. Dates, moments, and milliseconds are all accepted as input no matter what you specify for ```modelType```. However, strings are problematic and often lose timezone information, so use caution when storing strings.
-If you must use a string, be aware that the format stored in the model must exactly match the format specified in ```modelType```. For example, the value in the model is ```'2015-12-31'``` then using ```modelType: 'MM-DD-YYYY'``` will cause an exception.
-I predict that I will regret adding this feature.

closes #241, closes #190, closes #39
@dalelotts
Copy link
Owner

Closing since I believe this functionality is included in develop branch and it now has merge conflicts.

@dalelotts dalelotts closed this Jan 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants