Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions templates/poll.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,32 @@
{{ end }}
{{ end }}
<br />
<div id="vote-error" class="alert alert-danger d-none" role="alert"></div>
<button type="submit" class="btn btn-primary my-4 mx-4">Submit</button>
</form>
<!-- Handle error messages -->
<script>
document.querySelector('form[action^="/poll/"]').addEventListener('submit', async function(e) {
e.preventDefault();
const form = e.target;
const errorEl = document.getElementById('vote-error');
errorEl.classList.add('d-none');

const res = await fetch(form.action, {
method: 'POST',
body: new FormData(form),
});

if (res.redirected) {
window.location.href = res.url;
return;
}

const data = await res.json();
errorEl.textContent = data.error ?? 'An unknown error occurred.';
errorEl.classList.remove('d-none');
});
</script>
{{ if and (.CanModify) (not .Gatekeep) }}
<form action="/poll/{{ .Id }}/close" method="POST">
<button type="submit" class="btn btn-danger my-3 mx-4">End Poll</button>
Expand Down
Loading