From 782b2881191d1ff01a36e83fd7332194bcc0f218 Mon Sep 17 00:00:00 2001 From: Matt Helm Date: Thu, 6 Aug 2020 17:55:14 -0500 Subject: [PATCH 1/7] added Radio UI --- src/Builtins.jl | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Builtins.jl b/src/Builtins.jl index 578e6cd8..7618f0fa 100644 --- a/src/Builtins.jl +++ b/src/Builtins.jl @@ -1,4 +1,6 @@ -export Slider, NumberField, Button, CheckBox, TextField, Select, FilePicker +import Random: randstring + +export Slider, NumberField, Button, CheckBox, TextField, Select, FilePicker, Radio struct Slider range::AbstractRange @@ -127,4 +129,47 @@ function show(io::IO, ::MIME"text/html", filepicker::FilePicker) print(io, "'>") end -get(select::FilePicker) = Dict("name" => "", "data" => [], "type" => "") \ No newline at end of file +get(select::FilePicker) = Dict("name" => "", "data" => [], "type" => "") + +struct Radio + options::Array{Pair{AbstractString,Any},1} + default::AbstractString +end +Radio(options::Array{<:AbstractString,1}; default::AbstractString="") = Radio([o => o for o in options], default) + +function show(io::IO, ::MIME"text/html", radio::Radio) + groupname = randstring(12) + println(io, """
""") + for o in radio.options + println(io, """""") + println(io, """
""") + end + println(io, """
""") + println(io, """""") end \ No newline at end of file From 2827377f2395862ec353141e304d8a434c99d8b7 Mon Sep 17 00:00:00 2001 From: fonsp Date: Wed, 12 Aug 2020 14:59:23 +0000 Subject: [PATCH 3/7] withtag --- src/Builtins.jl | 75 +++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/Builtins.jl b/src/Builtins.jl index cdeaac34..1c3bd8f5 100644 --- a/src/Builtins.jl +++ b/src/Builtins.jl @@ -102,17 +102,17 @@ end Select(options::Array{<:AbstractString,1}) = Select([o => o for o in options]) function show(io::IO, ::MIME"text/html", select::Select) - println(io, """""") end get(select::Select) = first(select.options).first @@ -139,34 +139,35 @@ Radio(options::Array{<:AbstractString,1}; default::AbstractString="") = Radio([o function show(io::IO, ::MIME"text/html", radio::Radio) groupname = randstring(12) - println(io, """
""") - for o in radio.options - print(io, "
") - print(io, """""") - print(io, """""") - println(io, """
""") end - println(io, """
""") - println(io, """""") + withtag(io, :script) do + print(io, """ + const form = this.querySelector('#$(groupname)') + + form.oninput = (e) => { + form.value = e.target.value + // and bubble upwards + } + + // set initial value: + const selected_radio = form.querySelector('input[checked]') + if(selected_radio != null){ + form.value = selected_radio.value + } + """) + end end \ No newline at end of file From 35de4438b9b7f6742fe3503f5e94ef732e89c7c8 Mon Sep 17 00:00:00 2001 From: fonsp Date: Wed, 12 Aug 2020 15:33:42 +0000 Subject: [PATCH 4/7] docstring and refactor --- src/Builtins.jl | 52 +++++++++++++++++++++++++++++++++++-------------- src/PlutoUI.jl | 2 +- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/Builtins.jl b/src/Builtins.jl index 1c3bd8f5..ad5556df 100644 --- a/src/Builtins.jl +++ b/src/Builtins.jl @@ -66,9 +66,9 @@ Use `default` to set the initial value. See the [Mozilla docs about ``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text) and [`