Browse Source

Allow autocomplete selection value customization

tablepad
Trevor Slocum 2 years ago
parent
commit
018a7e47fe
  1. 1
      CHANGELOG
  2. 10
      inputfield.go

1
CHANGELOG

@ -5,6 +5,7 @@ v1.5.0 (WIP)
- Add InputField autocomplete style options
- Add arrow symbol to DropDown
- Add Makefile
- Allow autocomplete selection value customization
- Revamp FormItem styling as FormItem.SetAttributes
- Provide DropDownOption in DropDown handlers
- Provide ListItem in List handlers

10
inputfield.go

@ -102,7 +102,9 @@ type InputField struct {
// An optional autocomplete function which receives the current text of the
// input field and returns a slice of ListItems to be displayed in a drop-down
// selection.
// selection. Items' main text is displayed in the autocomplete list. When
// set, items' secondary text is used as the selection value. Otherwise,
// the main text is used.
autocomplete func(text string) []*ListItem
// The List object which shows the selectable autocomplete entries. If not
@ -872,8 +874,12 @@ func (i *InputField) InputHandler() func(event *tcell.EventKey, setFocus func(p
case tcell.KeyEnter: // We might be done.
if i.autocompleteList != nil {
currentItem := i.autocompleteList.GetCurrentItem()
selectionText := currentItem.mainText
if currentItem.secondaryText != "" {
selectionText = currentItem.secondaryText
}
i.Unlock()
i.SetText(currentItem.mainText)
i.SetText(selectionText)
i.Lock()
i.autocompleteList = nil
i.autocompleteListSuggestion = ""

Loading…
Cancel
Save