Multiple-Dates-Picker-for-jQuery-UI icon indicating copy to clipboard operation
Multiple-Dates-Picker-for-jQuery-UI copied to clipboard

Input multpleDatePickers Refreshes when selecting 3rd date

Open marnicsan opened this issue 8 years ago • 14 comments

Hi, i'm having troubles when i try to select more than 2 dates. When I select the 3rd date, the datepicker refresh to the start date and when I try to go back to a previous month it refreshes again to the start date. When finally I can refrech the 3rd and 4th dates it refreshs all over again. Here`s my code:

$('#datePick').multiDatesPicker({ maxPicks: $("#idAccidents").val(), changeMonth: true, changeYear: true, maxDate: 0 });

I have recently tested that it is also happening on your webpage [http://multidatespickr.sourceforge.net/] with the "FROM INPUT" example.

marnicsan avatar Jul 04 '16 04:07 marnicsan

I'm facing the exact same error. Would be great if this could be fixed :) Thanks already!

NickHeurter avatar Aug 03 '16 22:08 NickHeurter

@marnicsan did you already find a solution for this problem? I'm still facing this error.

NickHeurter avatar Aug 23 '16 14:08 NickHeurter

@marnicsan any solution so far?

NickHeurter avatar Nov 28 '16 14:11 NickHeurter

@NickHeurter I've found a hacky fix. The issue exists in jquery's date picker not in the multi date picker javascript.

$('#from-input').multiDatesPicker();
$.datepicker._selectDateOverload = $.datepicker._selectDate;
$.datepicker._selectDate = function (id, dateStr) {
  var target = $(id);
  var inst = this._getInst(target[0]);
  inst.inline = true;
  $.datepicker._selectDateOverload(id, dateStr);
  inst.inline = false;
  if (target[0].multiDatesPicker != null) {
    target[0].multiDatesPicker.changed = false;
  } else {
    target.multiDatesPicker.changed = false;
  }
  this._updateDatepicker(inst);
};

thomas0087 avatar Nov 29 '16 11:11 thomas0087

@thomas0087, great hacky fix dude! Thanks a lot, works like a charm.

NickHeurter avatar Nov 29 '16 12:11 NickHeurter

@thomas0087 It works fine dude! Thanks so much.

juanelobus avatar Jan 15 '17 04:01 juanelobus

@thomas0087 and anyone else trying to implement a multiple date picker in Javascript in 2017 (my heartfelt sympathies), for whatever reason, the script only worked for me when I replaced: $.datepicker._selectDateOverload(id, dateStr) with this._selectDateOverload(id, dateStr) Otherwise I was getting cannot read propert selectDateOverload of undefined. Works nicely afterward.

Thanks for the hack!

alphanumeric0101 avatar Nov 21 '17 23:11 alphanumeric0101

@thomas0087 Thanks! its work!

mypetertw avatar Mar 23 '18 04:03 mypetertw

It’s important in my app that the calendar stay fixed in place as dates are selected. Thomas’ fix works great, but the calendar no longer stays in place. Is there an easy fix?

jcerullo avatar Jun 23 '18 17:06 jcerullo

@thomas0087 thank you, you really helped me

Tynianov avatar Jun 23 '20 09:06 Tynianov

Awesome, thanks a lot!

Dimabytes avatar Jul 02 '20 21:07 Dimabytes

@thomas0087 2016 meets 2021, still works. However for those interested, I have improved upon the code from Thomas. I had a situation where I would have multiple datepickers on a single page, some with maxPicks not set, or set to 1, and some above 1. The code from Thomas had a small problem which was that when you would choose a date from a datepicker with maxPicks not set, or set to just 1, it would not close the datepicker automatically again like it would normally. At the bottom of the function $.datepicker._selectDate I added some code which takes care of that. Perhaps it might help someone one day.

$(el).multiDatesPicker(options);
$.datepicker._selectDateOverload = $.datepicker._selectDate;
$.datepicker._selectDate = function (id, dateStr) {
    var target = $(id);
    var inst = this._getInst(target[0]);
    inst.inline = true;
    $.datepicker._selectDateOverload(id, dateStr);
    inst.inline = false;
    if (target[0].multiDatesPicker != null) {
        target[0].multiDatesPicker.changed = false;
    } else {
        target.multiDatesPicker.changed = false;
    }
    this._updateDatepicker(inst);
    // Close datepicker if it isn't a so called Multi-datepicker, or when maxPicks is set to 1
    if(typeof inst.settings.maxPicks==='undefined' || inst.settings.maxPicks<=1 ){
        $(target).datepicker('hide');
    }
};

RensTillmann avatar Jan 14 '21 14:01 RensTillmann

@NickHeurter I've found a hacky fix. The issue exists in jquery's date picker not in the multi date picker javascript.

$('#from-input').multiDatesPicker();
$.datepicker._selectDateOverload = $.datepicker._selectDate;
$.datepicker._selectDate = function (id, dateStr) {
  var target = $(id);
  var inst = this._getInst(target[0]);
  inst.inline = true;
  $.datepicker._selectDateOverload(id, dateStr);
  inst.inline = false;
  if (target[0].multiDatesPicker != null) {
    target[0].multiDatesPicker.changed = false;
  } else {
    target.multiDatesPicker.changed = false;
  }
  this._updateDatepicker(inst);
};

Solution work only with one instance of multiDatesPicker in the page. I have two instance and I get the error:

Uncaught Missing instance data for this datepicker

how can I solve?

elia-c avatar Oct 12 '22 07:10 elia-c