diff options
author | Galen Guyer <galen@galenguyer.com> | 2022-08-11 14:59:09 -0400 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2022-08-11 14:59:09 -0400 |
commit | 8a4af84c69e90ec8410693072f90e44fb2ac5eb8 (patch) | |
tree | 5f6b3439b4611be8e83761b8f83e311cff508027 | |
parent | a96968f0c620b7070817883f88bee88febe6f69a (diff) |
Ensure Abstain is always present in simple custom votes
-rw-r--r-- | main.go | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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 +} |