Bootstrap-datepicker doesn't get fit with requirejs

I am building an application with backbone.js + require.js. I want to use datepicker from here in my application: datepicker

Since its non-AMD, I mask it in requirejs as follows:

require.config({
baseUrl: "appjs",

paths:{
    jquery: '../layout_assets/assets/js/libs/jquery-1.8.2.min',
    dt: '../layout_assets/plugins/datatables/jquery.dataTables.min',
    dtPlugins:'../layout_assets/plugins/datatables/dtplugins',
    dtBootstrap: '../layout_assets/plugins/datatables/dataTables.bootstrap',
    underscore: '../assets/js/underscore-min',
    Backbone: '../assets/js/backbone-min',
    bootstrap: '../assets/js/bootstrap.min',
    datepicker:'../layout_assets/bootstrap-datepicker'
    },

    shim: {
        underscore:{
            exports:"_"
        },

        Backbone:{
            deps: ['underscore','jquery'],
            exports: "Backbone"
        },

        dt: {
        deps:['jquery'],
        exports: "dt"   
        },

        dtPlugins: {
            deps:['jquery','dt'],
            exports:"dtPlugins"
            },
        bootstrap: {
        deps:['jquery'],
        exports:"bootstrap"

        },
        dtBootstrap: {
            deps: ['dt','jquery'],
            exports: "dtBootstrap"
        },

        datepicker:{
        deps:['jquery','bootstrap'],
        exports:"datepicker"
        }

        }

});

Now in one of my views, I call datepicker as follows:

define(['Backbone',
        'underscore',
        'jquery',
        'datepicker',
        'models/reports',
        'dtBootstrap',
        'bootstrap',
        'text!templates/reports/dashboard.html',
        ],function(Backbone,_,$,dp,report,dtBootstrap,bootstrap,dashboard){


        var view=Backbone.View.extend({
            el:"#content-wrap",
            template:_.template(dashboard),
            render:function(){
            this.$("#container-left").html(this.template());
            console.log(dp);
            }

    });
    return view;
    });

This returns undefined on the console. I think the library is not getting the right fit.

+5
source share
2 answers

This is the gasket I'm using:

"datepicker" : {
    deps: ["jquery-ui", "bootstrap"],
    exports: "$.fn.datepicker"
}

for

"datepicker": "lib/datepicker/js/bootstrap-datepicker"
+5
source

datepicker, , - requirejs dt "" (window.dt, ). - datepicker, jQuery, . docs:

$('#dp5').datepicker()
  .on('changeDate', function(ev){
    if (ev.date.valueOf() < startDate.valueOf()){
      ....
    }

});

- ?

, shimming .

0

All Articles