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

A config setting for invalid date message #229

Closed
musaffa opened this issue Mar 10, 2017 · 7 comments
Closed

A config setting for invalid date message #229

musaffa opened this issue Mar 10, 2017 · 7 comments

Comments

@musaffa
Copy link

musaffa commented Mar 10, 2017

A feature request.

Currently, if the date is invalid the template helper outputs Invalid date. The users might think there's something wrong in the data but if it is perfectly to valid to have empty dates. It is perhaps more desirable to display an empty "" or empty date message to the user instead of showing Invalid date. If there were a config option (global and local) to set a message which overrides this Invalid date message, this could have been easily solved. So if I set empty date in that config setting, this empty date message will show up instead of Invalid date.

Thanks.

@jasonmit
Copy link
Collaborator

jasonmit commented Mar 10, 2017

You can configure it to accept empty dates to avoid the Invalid Date output:
https://github.com/stefanpenner/ember-moment/blob/92a75466ce08715720204589e710481dd7b41dd7/README.md#global-allow-empty-dates

As for configuring the error message, "Invalid Date," that's handled internally within momentjs and I don't know off the top of my head if their is an API to configure it.

That said, I'd be happy to accept a pull request

@musaffa
Copy link
Author

musaffa commented Mar 10, 2017

I've already configured allowEmpty to true but Invalid date message is still an issue.

@jasonmit
Copy link
Collaborator

jasonmit commented Mar 11, 2017

@musaffa do you know what the value (empty string, null, or an invalid date string, etc.) you are passing into the helper is? Which helper are you using?

@musaffa
Copy link
Author

musaffa commented Mar 11, 2017

I'm using moment-format helper. As this helper already handles invalid dates, I don't to want to handle invalid dates myself. All I want is the ability to override the default output message with invalid dates.

This answer in SO suggests using moment.js' locale to override the message:

moment.updateLocale(moment.locale(), { invalidDate: "empty date" })

@jasonmit
Copy link
Collaborator

jasonmit commented Mar 12, 2017

@musaffa Assuming you are on the latest version, I'd expect that to snippet to still work with ember-moment.

@musaffa
Copy link
Author

musaffa commented Mar 12, 2017

I tried but it didn't work. ember-moment probably doesn't support updateLocale.

@jasonmit
Copy link
Collaborator

jasonmit commented Mar 13, 2017

@musaffa ember-cli-moment-shim (the thing you import moment with) is a very thin wrapper around momentjs. So, ember-moment really shouldn't be involved in the issue.

I would defer to opening an issue within momentjs if you need first-class support for changing this string.

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

No branches or pull requests

2 participants