adopted-ember-addons / ember-moment

MIT License
399 stars 122 forks source link

A config setting for invalid date message #229

Closed musaffa closed 7 years ago

musaffa commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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

jasonmit commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

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

musaffa commented 7 years ago

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

jasonmit commented 7 years ago

@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.