From 84361580be914b74833e1bff4089fb480049c989 Mon Sep 17 00:00:00 2001 From: BillyBlaze Date: Tue, 12 Dec 2017 18:15:54 +0000 Subject: [PATCH] :art: Jump to end of input When using the virtual keyboard, once opening, the cursor will jump to the end of the input field. --- octoprint_touchui/static/js/touchui.bundled.js | 10 +++++++--- source/js/components/keyboard.js | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/octoprint_touchui/static/js/touchui.bundled.js b/octoprint_touchui/static/js/touchui.bundled.js index fae3591d..d554d448 100644 --- a/octoprint_touchui/static/js/touchui.bundled.js +++ b/octoprint_touchui/static/js/touchui.bundled.js @@ -366,9 +366,13 @@ TouchUI.prototype.components.keyboard = { }, onShow: function(event, keyboard, el) { - // Set - var prev = keyboard.$preview.get(0); - prev.selectionStart = prev.selectionEnd = prev.value.length; + // Set the input cursor to the end of the input field + setTimeout(function() { + var prev = keyboard.$preview.get(0); + if (prev) { + prev.selectionStart = prev.selectionEnd = prev.value.length; + } + }, 10); keyboard.$keyboard.find("button").on("mousedown", function(e) { $(e.target).addClass("touch-focus"); diff --git a/source/js/components/keyboard.js b/source/js/components/keyboard.js index 460dc85f..5717df5e 100644 --- a/source/js/components/keyboard.js +++ b/source/js/components/keyboard.js @@ -143,9 +143,13 @@ TouchUI.prototype.components.keyboard = { }, onShow: function(event, keyboard, el) { - // Set - var prev = keyboard.$preview.get(0); - prev.selectionStart = prev.selectionEnd = prev.value.length; + // Set the input cursor to the end of the input field + setTimeout(function() { + var prev = keyboard.$preview.get(0); + if (prev) { + prev.selectionStart = prev.selectionEnd = prev.value.length; + } + }, 10); keyboard.$keyboard.find("button").on("mousedown", function(e) { $(e.target).addClass("touch-focus");