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

"date-range16" cannot be open with jquery #341

Closed tonyjames3212 closed 7 years ago

tonyjames3212 commented 7 years ago

jquery version: v2.0.3

When the mouse clicks the button open, it works fine. But it works not good with select:

  <select id="testsel">
    <option value="1">one</option>
    <option value="2">two</option>
    <option value="3">three</option>
  </select>

  $('#testsel').on("change",function(){
    if ($('#testsel').val()=="1"){
      $('#date-range16').data('dateRangePicker').open();
    }
  })

The datepicker closed immediately after it opend. Any idea?

tonyjames3212 commented 7 years ago

Fix it. I modified the code in jquery.datarangepicker.js:


            //if user click other place of the webpage, close date range picker window
            $(document).bind('click.datepicker', function(evt) {
                if (!IsOwnDatePickerClicked(evt, self[0])) {
                  try{
                    if (evt.toElement.className!="my-style"){
                      if (box.is(':visible')) closeDatePicker();
                    }
                  }catch(e){
                    if (box.is(':visible')) closeDatePicker();
                  }

                }
            });

and the select added the class:

  <select id="testsel" class="my-style">
    <option value="1">one</option>
    <option value="2">two</option>
    <option value="3">three</option>
  </select>

Thats it.

holtkamp commented 7 years ago

@tonyjames3212 so what did you change exactly? Might this be worth a Pull Request?

tonyjames3212 commented 7 years ago

@holtkamp I just changed it locally for my project.I'm not sure,should I create a branch for this?This plugin itself is good for use.

holtkamp commented 7 years ago

Well, apparently you changed this section

but you also introduced a specific classname my-style.

I think when used with a pulldown menu: the DateRangePicker opens when selecting an option from the pulldown, and directly closes again. I guess this is (for now) intended behaviour, so let's leave it at that..

Thanks for the feedback!