Added poll creation, srourcecode icon

This commit is contained in:
2021-04-04 21:23:20 +02:00
parent 4572e730f9
commit 67283a9474
8 changed files with 66 additions and 15 deletions

View File

@ -19,8 +19,8 @@ function validatePoll() {
}
const maxOptions = parseInt(form.querySelector('input[name=max_options]').value);
if (numOptionsProvided > 1 && (isNaN(maxOptions) || maxOptions <= 0 || maxOptions >= numOptionsProvided)) {
errors.push(`Max Options needs to be greater than 0 and smaller than ${numOptionsProvided}`);
if (numOptionsProvided > 1 && (isNaN(maxOptions) || maxOptions <= 0 || maxOptions > numOptionsProvided)) {
errors.push(`Max Options needs to at least 1 and not more than ${numOptionsProvided}`);
}
const durationDays = parseInt(form.querySelector('input[name=duration_days]').value);
@ -32,6 +32,10 @@ function validatePoll() {
errors.push('Duration must be more than 1 and less than 20160 minutes');
}
form.querySelector('input[name=duration_days] ~ span').innerText = durationDays === 1 ? 'day' : 'days';
form.querySelector('input[name=duration_hours] ~ span').innerText = durationHours === 1 ? 'hour' : 'hours';
form.querySelector('input[name=duration_minutes] ~ span').innerText = durationMinutes === 1 ? 'minute' : 'minutes';
const closesAtLabel = document.getElementById('openUntil');
if (!isNaN(durationTotalMinutes)) {
// Add duration_total_minutes to the curent Date

View File

@ -1,6 +1,6 @@
window.addEventListener('DOMContentLoaded', () => {
displayLocalTimestamps();
for (const el of document.querySelectorAll('.option input[type=checkbox]')) {
for (const el of document.querySelectorAll('.option input[type=checkbox], .option input[type=radio]')) {
el.onclick = updateVotesRemaining;
}
const banner = document.querySelector('.success-banner');
@ -31,7 +31,9 @@ function compareDateToToday(date) {
}
function updateVotesRemaining() {
const numChecked = document.querySelectorAll('.option input[type=checkbox]:checked').length;
const numChecked = document
.querySelectorAll('.option input[type=checkbox]:checked, .option input[type=radio]:checked')
.length;
const votesRemainingElement = document.querySelector('.votes-remaining');
const total = votesRemainingElement.dataset.maxVotes;
const remaining = Math.max(0, total - numChecked);