datepicker is not a function bootstrap-datepicker Symfony, webpack

I am stuck with following issue:
I have installed bootstrap-datepicker :

 "dependencies": {
    "bootstrap": "^4.4.1",
    "bootstrap-datepicker": "^1.9.0",
    "fontawesome": "^5.6.3",
    "jquery": "3.4.1",
    "popper": "^1.0.1"
}

My webpack.config:

 .addEntry('app',
    ['./assets/css/global.scss',
        './assets/js/app.js'
    ])
.addEntry('datepicker', [
    './assets/js/datepicker.js'
])

datepicker.js :

    // js
require('bootstrap-datepicker');
require('bootstrap-datepicker/js/locales/bootstrap-datepicker.fr');

// css
require('bootstrap-datepicker/dist/css/bootstrap-datepicker.css');


$(document).ready(function () { // you may need to change this code if you are not using Bootstrap Datepicker
    $('.js-datepicker').datepicker({format: 'yyyy-mm-dd'});
});

And app.js

const $ = require('jquery');
// this "modifies" the jquery module: adding behavior to it
// the bootstrap module doesn't export/return anything
require('bootstrap');

// any CSS you import will output into a single css file (app.css in this case)
import '../css/global.scss';
import '../css/foundation/_app.scss';
import '../css/foundation/_hero.scss';
import '../css/foundation/_minimal.scss';
import '../css/foundation/_tooltips.scss';
import '../css/foundation/_rating.scss';

I don’t know what’s going wrong, google doesn’t say much about it except the jquery version that is used by different modules is inconsistent.
When i create an alias for jquery in my webpack, I don’t get the error message anymore but nothing happens while clicking on the following field

     ->add('startDate', DateType::class, [
                'widget' => 'single_text',

                // prevents rendering it as type="date", to avoid HTML5 date pickers
                'html5' => false,

                // adds a class that can be selected in JavaScript
                'attr' => ['class' => 'js-datepicker'],
            ])

Thanks a lot for your help.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *