Search code examples
javascriptjquerytwitter-bootstraptwitter-bootstrap-3bootstrap-datetimepicker

How do I get the source for my events, with Bootstrap 3 DateTimePicker


I'm using Bootstrap 3 DateTimePicker but having some minor issues.

Basically, on the dp.show event, how do I get the source control? As far as I can tell, there is no parameter sent with the event, so I'm having a hard time figuring out which control actually showed.

(I have many pickers in my application)

Standard JQuery would tell me I could use e.Target, but there is no e sent with the event :(

How do I handle this?


Solution

  • You can attach a handler to your datepicker collection

    $('.datepicker').on('dp.show', function() {
        // this here will refer to the currently showing widget
        console.log(this);
    });
    

    This is the standard bootstrap way of dealing with events.

    EDIT: if you read the source code, the event is bound to the element with which the datepicker is initialized: https://github.com/Eonasdan/bootstrap-datetimepicker/blob/master/src/js/bootstrap-datetimepicker.js#L451