[icinga-checkins] icinga.org: icingaweb2/master: loader.js: place focus at the end of text inputs

git at icinga.org git at icinga.org
Mon Nov 21 12:39:58 CET 2016


Module: icingaweb2
Branch: master
Commit: d1fd7e4be78f3dda9734027dda53114b71a7a46d
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=d1fd7e4be78f3dda9734027dda53114b71a7a46d

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon Nov 21 11:39:03 2016 +0000

loader.js: place focus at the end of text inputs

---

 public/js/icinga/loader.js |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js
index cfa1cee..0966062 100644
--- a/public/js/icinga/loader.js
+++ b/public/js/icinga/loader.js
@@ -839,6 +839,15 @@
 
                     if ($activeElement.length && $activeElement.is(':visible')) {
                         $activeElement.focus();
+                        if ($activeElement.is('input[type=text]')) {
+                            if (typeof $activeElement[0].setSelectionRange === 'function') {
+                                // Place focus after the last character. Could be extended to other
+                                // input types, would require some \r\n "magic" to work around issues
+                                // with some browsers
+                                var len = $activeElement.val().length;
+                                $activeElement[0].setSelectionRange(len, len);
+                            }
+                        }
                     } else if (! autorefresh) {
                         if (focusFallback) {
                             $(focusFallback.parent).find(focusFallback.child).focus();



More information about the icinga-checkins mailing list