From cf6b24c5025b391b7c4e08af8ef7a071900beb2b Mon Sep 17 00:00:00 2001 From: David Florness Date: Tue, 19 Jan 2021 18:06:42 -0500 Subject: [PATCH] Don't create election if CreateElectionTUI form wasn't completed --- ui/tui.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ui/tui.go b/ui/tui.go index 1440aae..e3e8027 100644 --- a/ui/tui.go +++ b/ui/tui.go @@ -128,6 +128,9 @@ func RoomTUI(client *mautrix.Client, roomID id.RoomID, elections *election.Elect // user wants to create election (i == 0) title, candidates := CreateElectionTUI() + if candidates == nil { + return + } log.Debugf("title: %s", title) log.Debugf("candidates: %s", candidates) var err error @@ -197,9 +200,11 @@ func CreateElectionTUI() (title string, candidates []election.Candidate) { n-- } } + hitSubmit := false done := func() { // TODO: ensure none of the candidates are empty app.Stop() + hitSubmit = true title = form.GetFormItem(0).(*tview.InputField).GetText() for i := 1; i <= n; i++ { candidates = append(candidates, @@ -216,6 +221,10 @@ func CreateElectionTUI() (title string, candidates []election.Candidate) { if err := app.SetRoot(form, true).SetFocus(form).Run(); err != nil { panic(err) } + if !hitSubmit { + // user didn't hit submit button; consider form incomplete + return "", nil + } return title, candidates } -- 2.38.4