Hi @jlfsjunior,
I went through the link you provided and added the validation layout. But it seems not to work and I get the same error. I have provided my code for your reference if I am going wrong anywhere. Any help is much appreciated.
import dash
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, ALL, State, MATCH, ALLSMALLER
from dash_extensions.enrich import Output, DashProxy, Input, MultiplexerTransform
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP], suppress_callback_exceptions=True)
modal = html.Div(dbc.Modal([dbc.ModalBody(id='modal-body'),
dbc.ModalFooter(id='modal-footer',
children=dbc.Button(children='Close', id='close-modal', className='ml-auto',
n_clicks=0)),
],
id='modal',
centered=True,
is_open=False,
backdrop='static',
keyboard=True,
fade=True,
scrollable=True
),
)
modal_1 = 'Default selection'
modal_2 = 'Manual selection'
card = dbc.Card(dbc.CardBody(
[
dcc.Dropdown(id='src-vpc',
placeholder='select an item',
options=[{'label': 'label1', 'value': 'lable1'},
{'label': 'label2', 'value': 'lable2'},
{'label': 'label3', 'value': 'lable3'},
],
value=0,
style={'color': 'black'},
),
dbc.RadioItems(id='radio-items',
options=[{'label': 'Default value', 'value': 'default'},
{'label': 'Enter manually', 'value': 'manual'}],
value='default',
inline=True
),
html.Div(id='container'),
modal,
html.Button('Submit', id='button', n_clicks=0)
]))
manual = html.Div([
html.Br(),
dbc.Input(id='sel-manual',
placeholder='Enter a value',
type='text',
style={'color': 'black', 'width': '100%'}
),
])
default = html.Div([
html.Br(),
dcc.Dropdown(id='sel-default',
placeholder='select an item',
options=[{'label': 'dlabel1', 'value': 'dlable1'},
{'label': 'dlabel2', 'value': 'dlable2'},
{'label': 'dlabel3', 'value': 'dlable3'},
],
value=0,
style={'color': 'black'}
),
])
app.layout = html.Div(dbc.Row(dbc.Col(card, width=3)))
app.validation_layout = html.Div([card, modal, manual, default])
@app.callback(
Output(component_id='container', component_property='children'),
Input(component_id='radio-items', component_property='value'),
prevent_initial_call=True
)
def div_destination_node(dst_node):
print(f'Val of radio item: {dst_node}')
if dst_node == 'manual':
return manual
else:
return default
@app.callback(
[
Output('modal', 'is_open'),
Output('modal-body', 'children'),
],
[
Input('sel-manual', 'value'),
Input('sel-default', 'value'),
Input('radio-items', 'value'),
Input('button', 'n_clicks'),
Input('close-modal', 'n_clicks'),
],
prevent_initial_call=True
)
def radio_item_selection(val_manual, val_default, radio_item, n1, n2):
print(f'radio_item value:{radio_item}')
button_pressed = [p['prop_id'] for p in dash.callback_context.triggered][0]
print(f'button_pressed: {button_pressed}')
if 'close-modal' in button_pressed:
return False, ''
elif 'button' in button_pressed:
if radio_item == 'default':
print('value is hcloud')
return True, modal_1
else:
print('value is manual')
return True, modal_2
return False, ''
if __name__ == '__main__':
app.run_server(debug=True)
Thanks!