[GH-ISSUE #290] Bug in AddDropDown(); will not initialize correctly #224

Closed
opened 2026-03-04 01:03:07 +03:00 by kerem · 1 comment
Owner

Originally created by @mikeschinkel on GitHub (Jun 4, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/290

Currently in AddDropDown() you call SetCurrentOption(initialOption) before you call SetOptions(options, selected)) so the upshot is the parameter initialOption is ignored.

Here is the current code:

func (f *Form) AddDropDown(label string, options []string, initialOption int, selected func(option string, optionIndex int)) *Form {
	f.items = append(f.items, NewDropDown().
		SetLabel(label).
		SetCurrentOption(initialOption).
		SetOptions(options, selected))
	return f
}

Reversing the order resolves the issue:

func (f *Form) AddDropDown(label string, options []string, initialOption int, selected func(option string, optionIndex int)) *Form {
	f.items = append(f.items, NewDropDown().
		SetLabel(label).
		SetOptions(options, selected)).
		SetCurrentOption(initialOption)
	return f
}

I will submit a pull request.

Originally created by @mikeschinkel on GitHub (Jun 4, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/290 Currently in `AddDropDown()` you call `SetCurrentOption(initialOption)` **before** you call `SetOptions(options, selected))` so the upshot is the parameter `initialOption` is ignored. Here is the current code: ``` func (f *Form) AddDropDown(label string, options []string, initialOption int, selected func(option string, optionIndex int)) *Form { f.items = append(f.items, NewDropDown(). SetLabel(label). SetCurrentOption(initialOption). SetOptions(options, selected)) return f } ``` Reversing the order resolves the issue: ``` func (f *Form) AddDropDown(label string, options []string, initialOption int, selected func(option string, optionIndex int)) *Form { f.items = append(f.items, NewDropDown(). SetLabel(label). SetOptions(options, selected)). SetCurrentOption(initialOption) return f } ``` I will submit a pull request.
kerem closed this issue 2026-03-04 01:03:08 +03:00
Author
Owner

@rivo commented on GitHub (Jul 5, 2019):

Thanks!

<!-- gh-comment-id:508715129 --> @rivo commented on GitHub (Jul 5, 2019): Thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#224
No description provided.