Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix callback with multiple output referencing some component id #78

Merged
merged 2 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/handler/processors/callback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ function _push_to_res!(res, value, out::Vector)
_push_to_res!.(Ref(res), value, out)
end
function _push_to_res!(res, value, out)
!(value isa NoUpdate) && push!(res,
dep_id_string(out.id) => Dict(
Symbol(out.property) => DashBase.to_dash(value)
)
)
if !(value isa NoUpdate)
id = dep_id_string(out.id)
prop = Symbol(out.property)
dashval = DashBase.to_dash(value)
if haskey(res, id)
push!(res[id], prop => dashval)
else
push!(res, id => Dict{Symbol, Any}(prop => dashval))
end
end
end

_single_element_vect(e::T) where {T} = T[e]
Expand Down
26 changes: 26 additions & 0 deletions test/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,32 @@ end
@test haskey(app.callbacks, Symbol("my-div.children"))
@test app.callbacks[Symbol("my-div.children")].func("value", " value2") == "value value2"

end
@testset "callback! multi output same component id" begin
app = dash()
app.layout = html_div() do
dcc_input(id = "input-one",
placeholder = "text or number?")
dcc_input(id = "input-two",
placeholder = "")
end
callback!(app, Output("input-two","placeholder"), Output("input-two","type"),
Input("input-one","value")) do val1
if val1 in ["text", "number"]
return "$val1 ??", val1
end
return "invalid", nothing
end
@test length(app.callbacks) == 1
@test haskey(app.callbacks, Symbol("..input-two.placeholder...input-two.type.."))
@test app.callbacks[Symbol("..input-two.placeholder...input-two.type..")].func("text") == ("text ??", "text")
@test Dash.process_callback_call(app,
Symbol("..input-two.placeholder...input-two.type.."),
[(id = "input-two", property = "placeholder"),
(id = "input-two", property = "type")],
[(value = "text",)], [])[:response] == Dict("input-two" => Dict(:type => "text",
:placeholder => "text ??"))

end
@testset "callback! checks" begin

Expand Down