ghiscoding / Aurelia-Bootstrap-Plugins

Aurelia-Bootstrap-Plugins are Custom Elements to bridge with a set of 3rd party Bootstrap addons
https://ghiscoding.github.io/Aurelia-Bootstrap-Plugins
MIT License
45 stars 23 forks source link

Cannot change locale for aurelia-bootstrap-datepicker #12

Closed codeflowee closed 7 years ago

codeflowee commented 7 years ago

In my view:

<abp-datetime-picker value.bind="date" options.bind="{ format: 'DD-MM-YYYY', maxDate: 'now', locale: 'fi' }"></abp-datetime-picker>

Error in console:

Uncaught TypeError: locale() locale fi is not loaded from moment locales!
ghiscoding commented 7 years ago

Are you sure that your moment locale is installed? What happens when you do this in your ViewModel

moment.locale('fi');
console.log(moment(1316116057189).fromNow());
moment.locale('en');
console.log(moment(1316116057189).fromNow()); // an hour ago

What skeleton are you using, CLI, WebPack or ASP? Please provide more details about your setup, if you want help.

codeflowee commented 7 years ago

I am using aurelia-cli type project:

In view-model when I import moment via import moment from 'moment'; then in constructor the response for

    moment.locale('fi');
    console.log(moment(1316116057189).fromNow());
    moment.locale('en');
    console.log(moment(1316116057189).fromNow());

is

6 years ago
6 years ago

In aurelia.json I have following for this plugin:

{
  "name": "eonasdan-bootstrap-datetimepicker",
  "path": "../node_modules/eonasdan-bootstrap-datetimepicker/build",
  "main": "js/bootstrap-datetimepicker.min",
  "resources": [
    "css/bootstrap-datetimepicker.min.css"
  ]
},
{
  "name": "aurelia-bootstrap-datetimepicker",
  "path": "../node_modules/aurelia-bootstrap-datetimepicker/dist/amd",
  "main": "index",
  "resources": [
    "**/*.{css,html}"
  ]
},
"moment"
codeflowee commented 7 years ago

Okay, thanks for leading me on the right way:

What needed for this fix was:

{
  "name": "moment",
  "path": "../node_modules/moment",
  "main": "min/moment-with-locales"
}

in aurelia.json

This should be added into "How to" docs.

ghiscoding commented 7 years ago

Thanks a lot for the feedback, I added a note in the README under the Aurelia-CLI section of the aurelia-bootstrap-datetimepicker plugin. Also made it more clear under the WebPack version as well.

codeflowee commented 7 years ago

Thanks, keep up the good work! :+1:

ghiscoding commented 7 years ago

No problem, if you like the plugin, you can also click on the :star: to make it more popular :)