longbill / jquery-date-range-picker

A jQuery plugin that allows user to select a date range
MIT License
1.12k stars 579 forks source link

Error when trying to use the documented events #325

Open Stromwerk opened 7 years ago

Stromwerk commented 7 years ago

When trying to use the documented events I get a TypeError: Cannot read property 'is' of undefined. It's related to the box variable and the error is on line 876.

Here is my code

        var picker_from = $('#daterange-from');
        var picker_to = $('#daterange-to');
        picker_from.dateRangePicker({
            autoClose: true,
            container: '#calendar-container',
            customArrowPrevSymbol: '<i class="icon-left-arrow"></i>',
            customArrowNextSymbol: '<i class="icon-right-arrow"></i>',
            customTopBar: 'Заминаване',
            format: 'DD/MM/YYYY',
            inline: true,
            language: 'bg',
            singleMonth: true,
            singleDate: true,
            startOfWeek: 'monday',
            startDate: moment().format('DD/MM/YYYY')
        });
        picker_to.dateRangePicker({
            autoClose: true,
            container: '#calendar-container',
            customArrowPrevSymbol: '<i class="icon-left-arrow"></i>',
            customArrowNextSymbol: '<i class="icon-right-arrow"></i>',
            customTopBar: 'Връщане',
            format: 'DD/MM/YYYY',
            inline: true,
            language: 'bg',
            singleMonth: true,
            singleDate: true,
            startOfWeek: 'monday',
            startDate: moment().format('DD/MM/YYYY'),
        });
        $(document).on('click','#start-picker', function(e){
            e.stopPropagation();
            picker_to.data('dateRangePicker').close();
            picker_from.data('dateRangePicker').open();
        });
        $(document).on('click','#end-picker', function(e){
            e.stopPropagation();
            picker_from.data('dateRangePicker').close();
            picker_to.data('dateRangePicker').open();
        });
        picker_to.dateRangePicker().bind('datepicker-close',function(event,obj)
        {
            console.log(obj);
        });

When the last 4 lines are removed the picker works as expected, however when I try to bind an event, no matter what event I get the error. I have read issue #84 however that doesn't help me. I'm using jquery 1.11.1, but I also tried with 3.1.1 which is the newest as of the time of this writing. Also I'm using Moment 2.17.1