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 in window resize when binding events #466

Open jcubic opened 5 years ago

jcubic commented 5 years ago

There is error in the code, the docs say to use this to bind events:

$('#dom-id').dateRangePicker();

but this will create window resize event with box as undefined and will throw exception.

This is always added:

$(window).on('resize.datepicker', calcPosition);

even if you request for picker object to bind events. To fix the issue, is to use this code instead:

$('#dom-id').bind('datepicker-change', onChange);
monovertex commented 5 years ago

I'm not sure I understand what the issue is here. Can you provide a JSFiddle that showcases the bug?

jcubic commented 5 years ago

If you follow the API documentation, you have not working widget. so change event don't work at all as per API docs and instead you have exception in console. Will try to create fiddle with error using wrong API from docs. But right now I don't have access to the code I was using. It's on my work laptop.

jcubic commented 5 years ago

Here is fiddle https://jsfiddle.net/zcgtLehf/ if you call this

$('#dom-id')
.dateRangePicker()
.bind('datepicker-first-date-selected', function(event, obj) {
});

as per docs. And as per code, the plugin will be initialized twice but second time it will be broken. Open dev tools. When you focus the input, it will throw exception.