From d0202d73d329e9276615e92f3b9aebd13a8c6f99 Mon Sep 17 00:00:00 2001 From: Felix Niklas Date: Thu, 12 Apr 2018 12:18:23 +0200 Subject: [PATCH] Timepicker: fix highlight minutes & parse hour - fix highlight minutes when typing in the hour, fixes #1928 - parse hour when a column gets typed --- .../app/lib/bootstrap/bootstrap-timepicker.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/app/lib/bootstrap/bootstrap-timepicker.js b/app/assets/javascripts/app/lib/bootstrap/bootstrap-timepicker.js index 017c2a219..ac9667711 100644 --- a/app/assets/javascripts/app/lib/bootstrap/bootstrap-timepicker.js +++ b/app/assets/javascripts/app/lib/bootstrap/bootstrap-timepicker.js @@ -238,16 +238,29 @@ this.update(); break; case 8: // backspace - ignore + this.highlightedUnit = null; + break; + case 186: // colon + // value is "5" or "10" and a ":" was typed -> turn into 05:00 or 10:00 with 00 selected + if(this.$element.val().length <= 2){ + this.setTime(this.$element.val(), undefined, true); + this.$element.val(this.getTime()); + this.highlightMinute(); + e.preventDefault(); + } + if(this.highlightedUnit == 'hour'){ + setTimeout($.proxy(this.highlightNextUnit, this), 0); + e.preventDefault(); + } break; default: // all other keys // if cursor position is at the end of hour, jump to minute switch (this.getCursorPosition()) { case 1: - this.highlightMinute(); + // highlight minutes but async because the newly typed character is not yet stored in the value (happens after this event) + setTimeout($.proxy(this.highlightMinute, this), 0); break; - case 3: - } } },