trentrichardson / jQuery-Timepicker-Addon

Adds a timepicker to jQueryUI Datepicker
http://trentrichardson.com/examples/timepicker/
MIT License
2.66k stars 1.05k forks source link

Timepicker value gets reset after being set manually #644

Closed cptcrash80 closed 10 years ago

cptcrash80 commented 11 years ago

I have an event attached to the Timepicker that sets the textbox value to the current time when the user presses the space bar if the field is empty. Setting the value works fine. However, when _onTimeChange is ran it resets the value to 12;00 am. Does setting the value of the textbox not set the hidden value? I think it may also be because of the sliders (I'm using select).

Thanks in advance.

meyla commented 10 years ago

I was having this problem. I changed line 751 of the timepicker.js back to what it was in the previous version and it fixed the problem. I'm not sure what new problems this would cause, though. I edited the hasChanged evaluation to the following.

var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec || microsec != this.microsec || (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) || (this.timezone !== null && timezone != this.timezone));

cptcrash80 commented 10 years ago

Thanks for the reply. I switched the lines out and it works perfectly now.

Tomanow commented 10 years ago

Thank you meyla, I was also experiencing this issue.

bklaas commented 10 years ago

Thanks Meyla as well, the change fixed my issue.

I did a little extra debugging to figure out why the !== comparison operator caused the bug, and I determined that the offending part of the hasChanged logic for me was timezone.

console.debug(typeof timezone); console.debug(typeof this.timezone);

yields string number

Since the variables are of different type, using the strict !== operator returns false, which is not what's desired here. I'm not sure why you'd want strict comparison operators anywhere in that hasChanged logic, but it is timezone that is the issue on my machine, the rest of the variables are all of type number.

trentrichardson commented 10 years ago

I've updated the dev branch with a change to the hasChanged condition. Using the strict comparison is fine I think, it just needed to enforce the datatype. Can anyone verify the dev branch fixes their issue?

bklaas commented 10 years ago

Verified, that change works fine.

thanks for the quick support,

!/ben

On Thu, Nov 21, 2013 at 12:28 PM, Trent Richardson <notifications@github.com

wrote:

I've updated the dev branch with a change to the hasChanged condition. Using the strict comparison is fine I think, it just needed to enforce the datatype. Can anyone verify the dev branch fixes their issue?

— Reply to this email directly or view it on GitHubhttps://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/644#issuecomment-29009928 .