This is probably a simple solution, but I’ve been staring at it too long and can’t figure out why it’s not responding. I have a button next to an input that when clicked should clear the input. (Since the input doesn’t have an clearable option).
Here is the layout of the input and button:
dbc.Row([
html.Div([
html.P('Window:'),
dcc.Input(
type='number',
min=0,
style={'width': '100px'},
id={
'type': 'savgol-window',
'index': n1
}
),
dbc.Button(
'Clear',
color='secondary',
outline=True,
id={
'type': 'clear-savgol-window',
'input': n1
},
style={'width': '75px'},
n_clicks=0
)
],
style={'display': 'flex', 'justify-content': 'center', 'gap': '20px', 'align-items': 'baseline', 'margin-top': '20px'})
],
id={
"type": 'savgol-window-input',
'index': n1
})
and here is the callback:
@callback(
Output({'type': 'savgol-window', 'index': MATCH}, 'value'),
Input({'type': 'clear-savgol-window', 'index': MATCH}, 'n_clicks'),
State({'type': 'savgol-window', 'index': MATCH}, 'value')
)
def clear_savgol_input(n, value):
if ctx.triggered_id == 'clear-savgol-window':
return ''
else:
return value
Thoughts?