Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Protect against accidental double form submission, closes #722
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jul 8, 2021
1 parent f5af314 commit 1a79b1e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions vaccinate/templates/admin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ <h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('D
onLoadAddMap();

checkboxEditorForVaccinesOffered();

protectFormsAgainstDoubleSubmission();
});

var LEAFLET_CSS = "https://unpkg.com/[email protected]/dist/leaflet.css";
Expand Down Expand Up @@ -480,5 +482,24 @@ <h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('D
}
}

function protectForm(form) {
var locked = false;
form.addEventListener('submit', (ev) => {
if (locked) {
ev.preventDefault();
return;
}
locked = true;
setTimeout(() => {
locked = false;
}, 2000);
});
}

function protectFormsAgainstDoubleSubmission() {
Array.from(document.querySelectorAll('form')).forEach(protectForm);
}
</script>

</script>
{% endblock %}

0 comments on commit 1a79b1e

Please sign in to comment.