Fix counter main

* Fix crash when submitting nothing
* Fix code field not being autofocus
This commit is contained in:
2024-12-20 19:06:01 +01:00
parent a383f3e717
commit a548f4744e
2 changed files with 31 additions and 9 deletions

View File

@ -59,5 +59,26 @@
{% endif %}
{% endblock %}
{% block script %}
{{ super() }}
<script type="text/javascript">
window.addEventListener("DOMContentLoaded", () => {
// The login form annoyingly takes priority over the code form
// This is due to the loading time of the web component
// We can't rely on DOMContentLoaded to know if the component is there so we
// periodically run a script until the field is there
const autofocus = () => {
const field = document.querySelector("input[id='id_code']");
if (field === null){
setTimeout(autofocus, 0.5);
return;
}
field.focus();
}
autofocus()
})
</script>
{% endblock %}