Skip to content

Commit ecb3344

Browse files
authored
Merge pull request #78 from etpinard/fix-multioutput-same-dep-id
Fix callback with multiple output referencing some component id
2 parents 49dd231 + 02a1481 commit ecb3344

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/handler/processors/callback.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ function _push_to_res!(res, value, out::Vector)
2020
_push_to_res!.(Ref(res), value, out)
2121
end
2222
function _push_to_res!(res, value, out)
23-
!(value isa NoUpdate) && push!(res,
24-
dep_id_string(out.id) => Dict(
25-
Symbol(out.property) => DashBase.to_dash(value)
26-
)
27-
)
23+
if !(value isa NoUpdate)
24+
id = dep_id_string(out.id)
25+
prop = Symbol(out.property)
26+
dashval = DashBase.to_dash(value)
27+
if haskey(res, id)
28+
push!(res[id], prop => dashval)
29+
else
30+
push!(res, id => Dict{Symbol, Any}(prop => dashval))
31+
end
32+
end
2833
end
2934

3035
_single_element_vect(e::T) where {T} = T[e]

test/callbacks.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,32 @@ end
120120
@test haskey(app.callbacks, Symbol("my-div.children"))
121121
@test app.callbacks[Symbol("my-div.children")].func("value", " value2") == "value value2"
122122

123+
end
124+
@testset "callback! multi output same component id" begin
125+
app = dash()
126+
app.layout = html_div() do
127+
dcc_input(id = "input-one",
128+
placeholder = "text or number?")
129+
dcc_input(id = "input-two",
130+
placeholder = "")
131+
end
132+
callback!(app, Output("input-two","placeholder"), Output("input-two","type"),
133+
Input("input-one","value")) do val1
134+
if val1 in ["text", "number"]
135+
return "$val1 ??", val1
136+
end
137+
return "invalid", nothing
138+
end
139+
@test length(app.callbacks) == 1
140+
@test haskey(app.callbacks, Symbol("..input-two.placeholder...input-two.type.."))
141+
@test app.callbacks[Symbol("..input-two.placeholder...input-two.type..")].func("text") == ("text ??", "text")
142+
@test Dash.process_callback_call(app,
143+
Symbol("..input-two.placeholder...input-two.type.."),
144+
[(id = "input-two", property = "placeholder"),
145+
(id = "input-two", property = "type")],
146+
[(value = "text",)], [])[:response] == Dict("input-two" => Dict(:type => "text",
147+
:placeholder => "text ??"))
148+
123149
end
124150
@testset "callback! checks" begin
125151

0 commit comments

Comments
 (0)