From cc84c982fc1fc91616feb488f80725fdcb76c266 Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sat, 7 Apr 2018 12:58:52 +0200 Subject: [PATCH] Added GetFormItemByLabel(). Resolves #94 --- form.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/form.go b/form.go index 93fe9b2..5e424ab 100644 --- a/form.go +++ b/form.go @@ -246,6 +246,18 @@ func (f *Form) GetFormItem(index int) FormItem { return f.items[index] } +// GetFormItemByLabel returns the first form element with the given label. If +// no such element is found, nil is returned. Buttons are not searched and will +// therefore not be returned. +func (f *Form) GetFormItemByLabel(label string) FormItem { + for _, item := range f.items { + if item.GetLabel() == label { + return item + } + } + return nil +} + // SetCancelFunc sets a handler which is called when the user hits the Escape // key. func (f *Form) SetCancelFunc(callback func()) *Form {