@@ 328,10 328,18 @@ func VoteTUI(candidates []election.Candidate) []byte {
form.AddButton("Submit", func() {
app.Stop()
for i := 0; i < len(candidates); i++ {
- rank, err := strconv.Atoi(form.GetFormItem(i).(*tview.InputField).GetText())
+ text := form.GetFormItem(i).(*tview.InputField).GetText()
+ if text == "" {
+ ranks[i] = len(candidates)
+ continue
+ }
+ rank, err := strconv.Atoi(text)
if err != nil {
panic(err)
}
+ if rank > len(candidates) {
+ rank = len(candidates)
+ }
ranks[i] = rank
}
})