jquery-date-range-picker icon indicating copy to clipboard operation
jquery-date-range-picker copied to clipboard

Issue when working with same class on multiple fields

Open anupalhub opened this issue 9 years ago • 6 comments
trafficstars

Hi,

I have 3 daterange pickers with same class filterdaterange. For first one its opening fine BUT for second and third input the daterange picker is auto closing immedeately after opening. I don't want to write another jQuery selector and with different class How could i approach it with same class name on multiple fields?

JSFiddle: https://jsfiddle.net/anupalusoft/v8bpb76s/6/

anupalhub avatar Mar 18 '16 05:03 anupalhub

Can you provide a JSFiddle with an example that illustrates this use case?

holtkamp avatar Mar 18 '16 08:03 holtkamp

JSFiddle pasted in my question. Please check.

anupalhub avatar Mar 18 '16 08:03 anupalhub

mm, problem seems to be somewhere here https://github.com/longbill/jquery-date-range-picker/blob/4fb8159da3122cc7de753d26c47fb54d4c446c35/jquery.daterangepicker.js#L763-L768.

I don't have time to dive into this, but thanks for reporting this

holtkamp avatar Mar 18 '16 08:03 holtkamp

there is a simple way before code fixed

$(".class").each(function(index, element) {
$(element).dateRangePicker(......);
});

buburian avatar Mar 21 '16 07:03 buburian

@buburian I did the same way but not successful when using .bind('datepicker-open', function() for individuals. It becomes buggy and unresponsive for action applied with in .bind I will post a JSFiddle later.

anupalhub avatar Mar 21 '16 07:03 anupalhub

I have changed this function $(document).on('click.datepicker', outsideClickClose); to the following:

function outsideClickClose(evt) {
  var hasClickedOutside = true;
  var isVisible = function(elem) {
    return !!elem && !!(elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length);
  };

  self.each(function(index){
    if (self[index].contains(evt.target)) {
      if ( isVisible($('.date-picker-wrapper')[0]) ) {
        hasClickedOutside = false;
        }
    }
  });
      
      if(hasClickedOutside) {
          if (box.is(':visible')) closeDatePicker();
      }
  }

This worked for me.

teledirigido avatar May 04 '19 13:05 teledirigido