Hi everyone i have this div in my layout:
html.Div(style={'display':'flex'},
children=[
html.Button('Ajouter champ',
id='add-fieldtest',
className='button',
style={'width':'250px'}),
html.Button('Retirer champ',
id='remove-fieldtest',
className='button',
style={'width':'250px'}),
html.Button('Recherche',
id='search-buttontest',
className='button',
style={'width':'250px'})
]),
and these two call backs:
@app.callback(
Output('new-form', 'children'),
[Input('remove-fieldtest', 'n_clicks'),
Input('add-fieldtest', 'n_clicks')],
State('new-form', 'children')
)
def add_removefield(rem_n_clicks, add_n_clicks, children):
ctx = dash.callback_context
if not ctx.triggered:
return children
else:
btn_clicked = ctx.triggered[0]['prop_id'].split('.')[0]
if btn_clicked == 'remove-fieldtest':
del children[-1]
return children
else:
return children + [replicable_div]
@app.callback(
Output('footer', 'children'),
[Input('search-buttontest', 'n_clicks')],
State('new-form', 'children')
)
def searchtest(n_clicks, children):
print(get_btn_clicked())
if n_clicks is not None:
q = ""
for i in range(1, len(children)):
v = ''
q = q + children[i]['props']['children'][1]['props']['value']
print(q)
return html.Div()
The callback searchtest is triggered even when i click on “remove-fieldtest” or “add-fieldtest” buttons, i can’t tell what is wrong ?
When i click the remove and add buttons, both callbacks are triggered.