From 9967cf0a1d88c38d8d8854d08cfead1c89d21dc1 Mon Sep 17 00:00:00 2001 From: Tony Bradley Date: Fri, 14 Jun 2024 09:57:14 -0400 Subject: [PATCH 1/3] make callbacks configurable --- form.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/form.go b/form.go index a762303..8e31351 100644 --- a/form.go +++ b/form.go @@ -49,8 +49,8 @@ type Form struct { paginator paginator.Model // callbacks - submitCmd tea.Cmd - cancelCmd tea.Cmd + SubmitCmd tea.Cmd + CancelCmd tea.Cmd State FormState @@ -501,7 +501,7 @@ func (f *Form) Update(msg tea.Msg) (tea.Model, tea.Cmd) { f.aborted = true f.quitting = true f.State = StateAborted - return f, f.cancelCmd + return f, f.CancelCmd } case nextFieldMsg: @@ -517,7 +517,7 @@ func (f *Form) Update(msg tea.Msg) (tea.Model, tea.Cmd) { submit := func() (tea.Model, tea.Cmd) { f.quitting = true f.State = StateCompleted - return f, f.submitCmd + return f, f.SubmitCmd } if f.paginator.OnLastPage() { @@ -584,10 +584,25 @@ func (f *Form) View() string { return f.layout.View(f) } +type CallbackOptions struct { + SubmitCmd tea.Cmd + CancelCmd tea.Cmd +} + +func (f *Form) RunWithCallbacks(options CallbackOptions) error { + f.SubmitCmd = options.SubmitCmd + f.CancelCmd = options.CancelCmd + return f.Run() +} + // Run runs the form. func (f *Form) Run() error { - f.submitCmd = tea.Quit - f.cancelCmd = tea.Quit + if f.SubmitCmd == nil { + f.SubmitCmd = tea.Quit + } + if f.CancelCmd == nil { + f.CancelCmd = tea.Quit + } if len(f.groups) == 0 { return nil From b3e25fd44f07693b8695e43533f9a1226096a475 Mon Sep 17 00:00:00 2001 From: Tony Bradley Date: Fri, 14 Jun 2024 10:46:31 -0400 Subject: [PATCH 2/3] remove RunWithCallbacks --- form.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/form.go b/form.go index 8e31351..596c7c0 100644 --- a/form.go +++ b/form.go @@ -589,20 +589,10 @@ type CallbackOptions struct { CancelCmd tea.Cmd } -func (f *Form) RunWithCallbacks(options CallbackOptions) error { - f.SubmitCmd = options.SubmitCmd - f.CancelCmd = options.CancelCmd - return f.Run() -} - // Run runs the form. func (f *Form) Run() error { - if f.SubmitCmd == nil { - f.SubmitCmd = tea.Quit - } - if f.CancelCmd == nil { - f.CancelCmd = tea.Quit - } + f.SubmitCmd = tea.Quit + f.CancelCmd = tea.Quit if len(f.groups) == 0 { return nil From 6ce1e5da08999427f1fbb66cca9a49f57860cd32 Mon Sep 17 00:00:00 2001 From: Tony Bradley Date: Fri, 14 Jun 2024 10:47:01 -0400 Subject: [PATCH 3/3] remove callback options struct --- form.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/form.go b/form.go index 596c7c0..76e2788 100644 --- a/form.go +++ b/form.go @@ -584,11 +584,6 @@ func (f *Form) View() string { return f.layout.View(f) } -type CallbackOptions struct { - SubmitCmd tea.Cmd - CancelCmd tea.Cmd -} - // Run runs the form. func (f *Form) Run() error { f.SubmitCmd = tea.Quit