jQuery Datepicker - keep open after selecting a da

2019-03-06 10:11发布

问题:

I honestly hope you can help me with that as I have spent quite some time searching on the net for appropriate solutions and could not find any.

The issue I am having is that I have a jQuery datepicker which I would like to keep open after selecting a date and then close it when clicking the button "Done" underneath it. The closest thing I found is coming from a StackOverflow answer from 2012, but unfortunately it hides the buttons coming from the showButtonPanel: true option.

So this is a snapshot of my latest "try" which again it doesn't work:

$(function() {
  $(".datepicker").datepicker({
    showButtonPanel: true,
    onSelect: function(){
      $(this).val();
    }
  });
});

The calendar gets triggered from:

<input class="datepicker" type="text" path="startDate" data-date-format="mm/dd/yyyy" />

FYI - Im using jQuery 1.7.2.min.js (unfortunately I cannot update for safety and security reasons), jQuery-ui 1.10.3 and of course, Bootstrap (version 3.0.3 although I am not sure if this will help). Thank you

回答1:

Here is a working fiddle: http://jsfiddle.net/9uc7dwoa/

This is doing the trick in the onSelect:

if (inst.inline)
        this._updateDatepicker(inst);
else {
      this._hideDatepicker(null, this._get(inst, 'duration'));
      this._lastInput = inst.input[0];
      if (typeof(inst.input[0]) != 'object')
      inst.input[0].focus(); // restore focus
      this._lastInput = null;
}

Here the reference of the answer with the used code: jQuery Datepicker: Prevent closing picker when clicking a date