I would like to Enable/disable dropdowns when checkbox checked/unchecked
hi @Mallo
welcome to the community.
This is something you can do with Dash by using the dropdown’s disabled
property.
from dash import Dash, Output, Input, html, dcc, callback
app = Dash(__name__)
app.layout = html.Div([
dcc.Checklist(['product1','product2','product3'], id='checkbox-id'),
dcc.Dropdown(['A','B','C'], id='dropdown-id')
])
@callback(
Output('dropdown-id','disabled'),
Input('checkbox-id','value'),
Prevent_initial_call=True
)
def disable_dropdown(value):
if len(value) > 0:
return True
if len(value) == 0 or value is None:
return False
if __name__=='__main__':
app.run()
I have a problem when I click on the Watershed checkbox, the other dropdowns are still active. see the picture, please.
from dash import Dash, Output, Input, html, dcc, callback
import dash_daq as daq
app = Dash(name)
app.layout = html.Div([
html.H3(dcc.Checklist(['Watersheld'], id='checkbox-id')),
html.H3(children='Watersheld Seed Separation'),
daq.NumericInput(id='Watersheld-s-s'),
html.H3(children='Watersheld Seed Erosion'),
daq.NumericInput(id='watershed_erosion')
])
@callback(
Output('Watersheld-s-s','disabled'),
Output('watershed_erosion','disabled'),
Input('checkbox-id','value'),
Prevent_initial_call=True
)
def disable_dropdown(value):
if len(value) > 0:
return False
if len(value) == 0 or value is None:
return True
if name==‘main’:
app.run()
Hey @Mallo ,
from dash import Dash, Output, Input, html, dcc, callback
import dash_daq as daq
app = Dash(__name__)
app.layout = html.Div([
html.H3(dcc.Checklist(
['watershed'],
['watershed'],
id='checkbox-id')),
html.H3(children='Watersheld Seed Separation'),
daq.NumericInput(id='Watersheld-s-s'),
html.H3(children='Watersheld Seed Erosion'),
daq.NumericInput(id='watershed_erosion')
])
@callback(
Output('Watersheld-s-s','disabled'),
Output('watershed_erosion','disabled'),
Input('checkbox-id','value'),
Prevent_initial_call=True
)
def disable_dropdown(value):
if 'watershed' in value:
return True, True
else:
return False, False
if __name__=='__main__':
app.run()
Have a nice day.