Greetings,
I am trying to switch the values between two Input
Components and I have things halfway working.
The print behavior indicates that things should be working in my opinion. Below is the code:
...
dcc.Input(id='from-location', placeholder='Starting Location', size=50, style=dict(height=30)),
dcc.Input(id='to-location', placeholder='Destination', size=50, style=dict(height=30)),
daq.ToggleSwitch(id='switch-fields', label='Switch To/From', labelPosition='bottom'),
...
@app.callback(
Output('from-location', 'value'),
[Input('switch-fields', 'value')],
[State('from-location', 'value'),
State('to-location', 'value')]
)
def switch_field(switch, from_location, to_location):
if not switch:
print("start to field 1")
return from_location
else:
print("destination to field 1")
return to_location
@app.callback(
Output('to-location', 'value'),
[Input('switch-fields', 'value')],
[State('from-location', 'value'),
State('to-location', 'value')]
)
def switch_field(switch, from_location, to_location):
if switch:
print("start to field 2")
return from_location
else:
print("destination to field 2")
return to_location
Everytime the switch is clicked, the print behavior works as expected but the values only switch when the toggle becomes true. Any ideas?