aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-08-11 14:59:09 -0400
committerGalen Guyer <galen@galenguyer.com>2022-08-11 14:59:09 -0400
commit8a4af84c69e90ec8410693072f90e44fb2ac5eb8 (patch)
tree5f6b3439b4611be8e83761b8f83e311cff508027
parenta96968f0c620b7070817883f88bee88febe6f69a (diff)
Ensure Abstain is always present in simple custom votes
-rw-r--r--main.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/main.go b/main.go
index d395a6d..2ddf04e 100644
--- a/main.go
+++ b/main.go
@@ -130,6 +130,9 @@ func main() {
poll.Options = []string{}
for _, opt := range strings.Split(c.PostForm("customOptions"), ",") {
poll.Options = append(poll.Options, strings.TrimSpace(opt))
+ if !containsString(poll.Options, "Abstain") && (poll.VoteType == database.POLL_TYPE_SIMPLE) {
+ poll.Options = append(poll.Options, "Abstain")
+ }
}
case "pass-fail":
default:
@@ -403,3 +406,12 @@ func hasOption(poll *database.Poll, option string) bool {
}
return false
}
+
+func containsString(arr []string, val string) bool {
+ for _, a := range arr {
+ if a == val {
+ return true
+ }
+ }
+ return false
+}