will callback be trigger when a button’s ancestors deleted? I run below code
app.layout = html.Div(
id = "main",
children=[
html.Div(
id="{type: 'card', index: 0}",
children=[
html.Div(
id="{type: 'add', index: 0}",
children=[html.Button(id={'type': 'add-button', 'index': 0}, children="Add")],
),
html.Div(
id="{type: 'delete', index: 0}",
children=[html.Button(id={'type': 'delete-button', 'index': 0}, children="Delete")],
),
],
),
html.Div(
id="{type: 'card', index: 1}",
children=[
html.Div(
id="{type: 'add', index: 1}",
children=[html.Button(id={'type': 'add-button', 'index': 1}, children="Add")],
),
html.Div(
id="{type: 'delete', index: 1}",
children=[html.Button(id={'type': 'delete-button', 'index': 1}, children="Delete")],
),
],
),
]
)
@app.callback(
Output("main", "children", allow_duplicate=True),
Input({'type': 'delete-button', 'index': ALL}, 'n_clicks'),
State("main", "children"),
prevent_initial_call=True
)
def delete(n_clicks, children):
button_id = ctx.triggered_id["index"]
print("__delete__")
print(ctx.triggered)
if ctx.triggered[0].get("value") is None:
raise dash.exceptions.PreventUpdate
else:
p = Patch()
del p[button_id]
return p
@app.callback(
Output("main", "children", allow_duplicate=True),
Input({'type': 'add-button', 'index': ALL}, 'n_clicks'),
State("main", "children"),
prevent_initial_call=True
)
def add(n_clicks, children):
button_id = ctx.triggered_id["index"]
print("__add__")
print(ctx.triggered)
if ctx.triggered[0].get("value") is None:
raise dash.exceptions.PreventUpdate
else:
p = Patch()
p.insert(button_id + 1, html.Div(id="{type: 'card', index: 2}"))
return p
if __name__ == "__main__":
app.run_server(debug=True)
When i click delete button index of 1, add button alse be triggered, but having n_clicks of 0