question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using an Observable List with Select Form

See original GitHub issue

I might be using Select form the wrong way, but I have an internal API that returns an observable list which I would like to use in a select box. I’m not sure how to make the select options update with the new elements added to the observable list. This is what I have so far:

class SomeContainer: SimplePanel() {
    var someList: ObservableList<Pair<String, String>> = observableListOf()
    init {
        val formPanel = formPanel<SomeForm> {
            add(
                    SomeForm::select,
                    Select(
                            label = "Simple select"
                    ).also {
                        options = someList
                        liveSearch = true
                    }
            )
        }
        someList.add(Pair("someValue", "someLabel"))
        someList.add(Pair("someOtherValue", "someOtherLabel"))
        .....
    }
}

The result is an empty options list when selecting, perhaps this is expected since options expects a non-mutable list. Is there any way to do this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
rjaroscommented, Mar 14, 2019

And remeber to add the Select component to the FormPanel after the DataContainer is created. It’s important, because it must be a child of some visual container (one “connected” to the root component).

1reaction
rjaroscommented, Mar 14, 2019

The options parameter of the Select component is designed for static usage. To have dynamic list of options use the DataContainer as a non-visual wrapper, like that:

val someList: ObservableList<Pair<String, String>> = observableListOf()
val select = Select(label = "Simple select").apply {
    liveSearch = true
}
DataContainer(someList, { pair, _, _ -> SelectOption(pair.first, pair.second) }, select)
add(SomeForm::select, select)
Read more comments on GitHub >

github_iconTop Results From Across the Web

ObservableList (JavaFX 8) - Oracle Help Center
Creates a SortedList wrapper of this list using the specified comparator. Methods inherited from interface java.util.List · add, add, addAll, addAll, clear, ...
Read more >
How to properly implement observable list to populate a ...
In my project, a table view is being populated with information based on what value is currently selected in the combo box. And...
Read more >
Inputs.select - Observable
A Select allows the user to choose from a given set of values. A Select is recommended over a Radio or a Checkbox...
Read more >
JavaFX Tutorial - Observable List example with Combo Box
JavaFX tutorial on observablelist. We go over examples with binding to a ComboBox. Multiple techniques are covered such as binding in the ...
Read more >
JavaFX Tutorial 13 - ComboBox, ObservableList (Remastered)
The ComboBox is also known as choice list or dropdown list that contains a list of items from which the user can choose....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found