mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-07 22:25:35 +00:00
Improve TOTP auto-submit code
* Listen to "input" event only, don't need "keyup" * Add form double-submit protection * Rewrite in plain JS (the page no longer loads jQuery)
This commit is contained in:
parent
daad54aea9
commit
decd1d4b87
2 changed files with 15 additions and 4 deletions
|
@ -1,7 +1,15 @@
|
|||
$(function() {
|
||||
$("input[data-auto-submit]").on("keyup input", function() {
|
||||
if (this.validity.valid) {
|
||||
window.addEventListener("DOMContentLoaded", function(e) {
|
||||
var validateAndSubmit = function() {
|
||||
if (this.validity.valid && !this.dataset.submitted) {
|
||||
// Make sure we only submit the form once
|
||||
this.dataset.submitted = true;
|
||||
this.form.submit();
|
||||
}
|
||||
}
|
||||
|
||||
// Hook up validateAndSubmit to all input elements with the
|
||||
// "data-auto-submit" attribute
|
||||
document.querySelectorAll("input[data-auto-submit]").forEach((input) => {
|
||||
input.addEventListener("input", validateAndSubmit);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
pattern="[0-9]{6}"
|
||||
title="6-digit code"
|
||||
placeholder="6-digit code"
|
||||
data-auto-submit="1"
|
||||
class="form-control input-lg"
|
||||
required
|
||||
autofocus />
|
||||
|
@ -41,6 +42,8 @@
|
|||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block base_scripts %}{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
{% compress js %}
|
||||
<script src="{% static 'js/auto-submit.js' %}"></script>
|
||||
|
|
Loading…
Add table
Reference in a new issue