aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-17 16:07:27 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-17 16:07:27 +0800
commita8ca7e38d78abf58ebe432aa261a1e0d3cd6b7fc (patch)
treeaa42b59e014cce57c2597d5ac076d89c987ea4a7 /fg21sim
parent030125051f33127b542c85b35d9ce8dafa92aabe (diff)
downloadfg21sim-a8ca7e38d78abf58ebe432aa261a1e0d3cd6b7fc.tar.bz2
webui: login: Submit login form on "Enter" key
Diffstat (limited to 'fg21sim')
-rw-r--r--fg21sim/webui/static/js/login.js23
-rw-r--r--fg21sim/webui/templates/login.html6
2 files changed, 28 insertions, 1 deletions
diff --git a/fg21sim/webui/static/js/login.js b/fg21sim/webui/static/js/login.js
new file mode 100644
index 0000000..301de73
--- /dev/null
+++ b/fg21sim/webui/static/js/login.js
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2016 Weitian LI <liweitianux@live.com>
+ * MIT license
+ *
+ * JavaScript codes for the Web UI of "fg21sim"
+ */
+
+"use strict";
+
+
+$(document).ready(function () {
+ /**
+ * Submit the login form on "Enter" key
+ * Credit: https://stackoverflow.com/a/12518467/4856091
+ */
+ $("form#login input").keypress(function (e) {
+ if (e.which === 13) {
+ // "Enter" key pressed
+ $(e.target).closest("form").submit();
+ return false;
+ }
+ });
+});
diff --git a/fg21sim/webui/templates/login.html b/fg21sim/webui/templates/login.html
index 51d4cd1..e0e98da 100644
--- a/fg21sim/webui/templates/login.html
+++ b/fg21sim/webui/templates/login.html
@@ -14,7 +14,7 @@
<h2><span class="fa fa-key" aria-hidden="true"></span> Login</h2>
<hr />
- <form action="/login" method="post">
+ <form id="login" action="/login" method="post">
{% module xsrf_form_html() %}
<fieldset>
<label for="password">Password:
@@ -28,3 +28,7 @@
</form>
</section>
{% end %}
+
+{% block extra_script %}
+ <script src="{{ static_url('js/login.js') }}"></script>
+{% end %}