question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue when working with same class on multiple fields

See original GitHub issue

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/

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
buburiancommented, Mar 21, 2016

there is a simple way before code fixed

$(".class").each(function(index, element) {
$(element).dateRangePicker(......);
});
0reactions
teledirigidocommented, May 4, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple input fields with same class calling same function not ...
I'm trying to call the same ajax function from multiple input fields. I followed this link and when I tested that code its...
Read more >
9. Classes — Python 3.11.1 documentation
Creating a new class creates a new type of object, allowing new instances of ... and multiple names (in multiple scopes) can be...
Read more >
How do I bind this to multiple input fields with the same class ...
I see you bind it to an element with the ID #autocomplete, but if I try to bind it to more than one...
Read more >
Understanding Class Members (The Java™ Tutorials ...
In this section, we discuss the use of the static keyword to create fields and methods that belong to the class, rather than...
Read more >
Object orientation - The Apache Groovy programming language
There are at least two important differences of choosing one or another. First, while abstract classes may contain fields/properties and concrete methods, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found