forked from tslocum/cview
fix(form/GetFormItem): Check whether index is out of bounds, if so, return nil
This commit is contained in:
parent
8bd1023ddc
commit
367d377081
8
form.go
8
form.go
|
@ -466,12 +466,14 @@ func (f *Form) IndexOfFormItem(item FormItem) int {
|
|||
}
|
||||
|
||||
// GetFormItem returns the form item at the given position, starting with index
|
||||
// 0. Elements are referenced in the order they were added. Buttons are not
|
||||
// included.
|
||||
// 0. Elements are referenced in the order they were added. Buttons are not included.
|
||||
// If index is out of bounds it returns nil.
|
||||
func (f *Form) GetFormItem(index int) FormItem {
|
||||
f.RLock()
|
||||
defer f.RUnlock()
|
||||
|
||||
if index > len(f.items)-1 || index < 0 {
|
||||
return nil
|
||||
}
|
||||
return f.items[index]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue