From 585e04463f16d2423dc745c60e9c989ef74f76ca Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 16 Oct 2022 18:36:01 +0800 Subject: [PATCH] Support mixed String/Pair entries in Dropdown --- lib/Surveys.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Surveys.jl b/lib/Surveys.jl index dfef7e0..abc8969 100644 --- a/lib/Surveys.jl +++ b/lib/Surveys.jl @@ -464,6 +464,18 @@ Dropdown(opts::Union{Vector{String}, Vector{Pair{String, String}}}) = Dropdown(Options(opts)) Dropdown(gopts::Vector{Pair{String, Vector}}) = Dropdown([OptGroup(gopt) for gopt in gopts]) +Dropdown(opts::Vector{Any}) = + if Pair{String,String} in typeof.(opts) + opts = map(opts) do o + if o isa String + o => o + else + o + end + end |> Vector{Pair{String,String}} |> Dropdown + else + throw(ArgumentError("Expecected opts to be a Vector{Union{String, Pair{String, String}}}.")) + end html_element(::Dropdown) = "select" function html_content(d::Dropdown{Options}, value)