2

I am building a wonderful web application with Laravel, defining my javascript dependencies with the package.json, and all is going well. Until when I need to use a JQuery datepicker with a default italian localization.

Looking in SO, I get a million of suggestions about JQuery-UI and localization, like JQuery UI datepicker localization, Localization not working in jQuery UI datePicker and jQuery UI Datepicker localization error on load . Sadly, nothing about how to make it work with NPM and moreover with a localization file needed.

I could download the source files and use them, but I managed to be tidy until now, and I'd love to find out how to use NPM for my datepicker too.

1 Answer 1

1

After a ton of attempts, here is a working version.

First of all, define all of the dependencies in package.json

...
"jquery-ui-dist": "^1.12.1",
"jquery-ui": "^1.12.1",
...

Notice that I need BOTH the jquery-ui-dist version (for the minimized version that we will use) and the jquery-ui, for the localization file.

That said, I have to copy my files from the node_modules folder (that I don't export in production) to the public/js folder, and I do it adding these rows in webpack.mix.js

...
.scripts('node_modules/jquery-ui-dist/jquery-ui.min.js','public/js/jquery-ui.min.js')
.scripts('node_modules/jquery-ui/ui/i18n/datepicker-it.js','public/js/datepicker-it.js')
...

Last but not least, I add the import of the javascript files in my page,

<script src="/js/jquery-ui.min.js"></script>
<script src="/js/datepicker-it.js"></script>

and this makes the trick, loading the datepicker in italian language by default

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.