Skip to content

Commit

Permalink
Update Bonds.possible_values for transformed bonds
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Nov 9, 2021
1 parent 1ea9898 commit 9eb6f71
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PlutoUI"
uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
authors = ["Fons van der Plas <[email protected]>"]
version = "0.7.18"
version = "0.7.19"

[deps]
AbstractPlutoDingetjes = "6e696c72-6542-2067-7265-42206c756150"
Expand Down
6 changes: 4 additions & 2 deletions src/Builtins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ begin
Base.get(slider::Slider) = slider.default
Bonds.initial_value(slider::Slider) = slider.default

Bonds.possible_values(slider::Slider) = slider.range
Bonds.possible_values(slider::Slider) = 1:length(slider.values)

function Bonds.transform_value(slider::Slider, val_from_js)
slider.values[val_from_js]
Expand Down Expand Up @@ -580,14 +580,16 @@ begin
Base.get(select::Select) = select.default
Bonds.initial_value(select::Select) = select.default

Bonds.possible_values(select::Select) = (o.first for o in select.options)
Bonds.possible_values(select::Select) = (string(i) for i in 1:length(select.options))

function Bonds.transform_value(select::Select, val_from_js)
# val_from_js will be a String, but let's allow Integers as well, there's no harm in that
val_num = val_from_js isa Integer ? val_from_js : tryparse(Int64, val_from_js)
select.options[val_num].first
end

function Bonds.validate_value(select::Select, val_from_js)
# val_from_js will be a String, but let's allow Integers as well, there's no harm in that
val_num = val_from_js isa Integer ? val_from_js : tryparse(Int64, val_from_js)
val_num isa Integer && 1 <= val_num <= length(select.options)
end
Expand Down

2 comments on commit 9eb6f71

@fonsp
Copy link
Member Author

@fonsp fonsp commented on 9eb6f71 Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/48468

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.19 -m "<description of version>" 9eb6f719873780a00fe43138b8afb787d2066621
git push origin v0.7.19

Please sign in to comment.