Files
grecia/app/assets/javascripts/polls/form.js
werdenktwas-gmbh abf02808bf Disable other answers when reaching maximum votes
This is similar to the way we were disabling buttons in the old design.

Co-authored-by: Javi Martín <javim@elretirao.net>
2025-08-14 13:06:43 +02:00

28 lines
868 B
JavaScript

(function() {
"use strict";
App.PollsForm = {
updateMultipleChoiceStatus: function(fieldset) {
var max_votes = $(fieldset).attr("data-max-votes");
var checked_boxes = $(fieldset).find(":checkbox:checked");
var unchecked_boxes = $(fieldset).find(":checkbox:not(:checked)");
if (checked_boxes.length >= max_votes) {
$(unchecked_boxes).prop("disabled", true);
} else {
$(fieldset).find(":checkbox").prop("disabled", false);
}
},
initialize: function() {
$(".poll-form .multiple-choice").each(function() {
App.PollsForm.updateMultipleChoiceStatus(this);
});
$(".poll-form .multiple-choice :checkbox").on("change", function() {
var fieldset = $(this).closest("fieldset");
App.PollsForm.updateMultipleChoiceStatus(fieldset);
});
}
};
}).call(this);