clockpicker
clockpicker copied to clipboard
Picker does not work with type="time" inputs when twelvehour=true
When the option "twelvehour" = true, the text "AM"/"PM" is added to the output string.
This is great for TEXT inputs, but does not work for TIME inputs. TIME inputs expect a value in the format of HH:MM:SS.
The easiest way to account for this is down in the "ClockPicker.prototype.done" function:
- Only do the following steps if the TYPE of the input is "time".
- Increment the hours+12 if this.amOrPm==="PM".
- Do not include the "AM"/"PM" in the final output string.
- Append ":00" (Zero seconds) to the output string.
The line to determine am/pm doesn't work. I changed it to this and it works fine: this.amOrPm = this.hours > 12 || period === 'pm' ? 'PM' : 'AM';
Even after I made the corrections above, we were still having problems if they picked 12. Did they mean noon or midnight?
And after reading this http://www.simplecodeworks.com/IQ/midnight.html, I decided to switch to the 24 hour clock.
Seriously, go read it! :-)
This is the code that works for me, replacing https://github.com/weareoutman/clockpicker/blob/gh-pages/src/clockpicker.js#L679:
if (this.options.twelvehour) {
if (this.input.attr('type') === 'time') {
var hoursInMilitary = (this.amOrPm === 'PM') ? this.hours + 12 : this.hours;
value = leadingZero(hoursInMilitary) + ':' + leadingZero(this.minutes);
value = value + ':00';
}
else {
value = value + this.amOrPm;
}
}
I have the same problem... I don't want to edit the source though... I'll just use type=text for now.
Puedes editar las siguientes lineas https://github.com/weareoutman/clockpicker/blob/gh-pages/src/clockpicker.js#L465
` this.hours = +value[0] || 0; if (this.options.twelvehour) { this.minutes = +value[1].split(' ')[0] || 0; this.amOrPm = +value[1].split(' ')[1] || 'AM'; } else { this.minutes = +value[1] || 0; } this.spanHours.html(leadingZero(this.hours)); this.spanMinutes.html(leadingZero(this.minutes)); if (this.options.twelvehour) { this.spanAmPm.html(' ' + this.amOrPm); }
`