SimonDanisch / Bonito.jl

Serving JS to the browser
MIT License
204 stars 29 forks source link

update Dropdown programmatically #218

Closed bjarthur closed 4 months ago

bjarthur commented 5 months ago

previously, you could update option_index programmatically, but the display wouldn't change. now it does.

julia> using Bonito, Observables

julia> options = Observable(["a","b","c"])
Observable(["a", "b", "c"])

julia> V = []
Any[]

julia> app = App() do
           dd = Dropdown(options[])
           push!(V, (; dd))
           return dd
       end

julia> V[1].dd.option_index[]
1

julia> V[1].dd.option_index[]=2
2
bjarthur commented 5 months ago

the second commit in the PR will also cause the display to update when changing the options list programmatically. works fine when the current index is less than the length of the new options, but throws this error otherwise:

julia> V[1].dd.options[] = ["1","2"]
ERROR: BoundsError: attempt to access 2-element Vector{Any} at index [3]

looking into how to fix this now. suggestions welcome!

bjarthur commented 4 months ago

@SimonDanisch thoughts? i been using this PR in a dev branch and it seems fine so long as the developer makes sure the index does not exceed the length of the options.

SimonDanisch commented 4 months ago

Merged in https://github.com/SimonDanisch/Bonito.jl/pull/225