amsul / pickadate.js

The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
http://amsul.ca/pickadate.js
MIT License
7.7k stars 1.01k forks source link

onSet returning a Number on Mouse selection, an Object on select via Keyboard (pressing enter) #561

Open DanielDornhardt opened 10 years ago

DanielDornhardt commented 10 years ago

Hello,

One of my clients discovered that the date wasn't saved correctly when he was tabbing through a form and selecting the value of the datepicker via the keyboard and pressing enter.

Upon debugging the issue, I noticed that indeed the datepicker supplies different values, depending on whether the keyboard or the mouse was used to trigger the selection:

Code in onSet - callback:

onSet: function(context) {
  console.log(context, typeof context.select);
}

Selecting a date with the mouse returns this:

Object {select: 1416355200000} "number"

Selecting a date via keyboard returns this:

Object {select: Object} "object"

The object looks nice, and I can definitely use it, but I just wanted to let you know that it's an issue people who would use onSet: without testing keyboard interaction could stumble about:

image

Anyways, the datepicker itself is awesome, and very well supported, very professional, I can't thank you enough.

Best wishes

Daniel

amsul commented 9 years ago

Ah, yes - that is an unfortunate oversight within the API.

This will be resolved as of v4 because proper event objects will be used. Keeping this open until then.

Appreciate you bringing this up!

DanielDornhardt commented 9 years ago

Maybe it would be nice to add a reference / short explanation to the docs on how to normalize the result in onSet for the current version?

I'm right now not able to properly create a pull request, but maybe the code I am using is helpful as an example to somebody:

onSet: function(context) {
  var val;
  if (!(context != null ? context.select : void 0)) {
    return '';
  }
  val = context.select;
  if ('object' === typeof val) {
    return val = val.obj.getTime();
  }
}

Maybe you could add some of it to the http://amsul.ca/pickadate.js/date.htm - help at the bottom, where the onSet - callback is described.

Thanks & best wishes

Daniel

JiriPelnar commented 6 years ago

Just noticed this issue while playing with the onSet callback. Would be great to see this implemented in some future version.