Это работает для отключения и повторного включения поля ввода, но оно теряет фокус при повторном включении. Как вернуть фокус?
Код: Выделить всё
from dash import Dash, html, callback, Output, Input, dcc
from time import sleep
input_tag = dcc.Input(id='input', debounce=0.500, autoFocus=True)
output_tag = dcc.Input(id='output', disabled=True)
app = Dash(__name__,)
app.layout = [html.Div([input_tag, output_tag]),]
@callback(
Output('output', 'value'),
Input('input', 'value'),
prevent_initial_call=True,
running=[(Output('input', 'disabled'), True, False)]
)
def process(value: str):
sleep(2)
return value
if __name__ == '__main__':
app.run(debug=True)
Код: Выделить всё
from dash import Dash, html, callback, Output, Input, dcc
from time import sleep
import dash_bootstrap_components as dbc
input_tag = dbc.Input(id='input', debounce=500, autoFocus=True)
output_tag = dbc.Input(id='output', disabled=True)
app = Dash(__name__,)
app.layout = [
html.Div([input_tag, dcc.Loading(
children=html.Div(id='spinner_div'),type='circle',)]
, style={'width': 'fit-content'}
),
html.Div([output_tag]),
]
app.clientside_callback(
"""
function(disabled) {
if (disabled === false) {
const el = document.getElementById('input');
if (el) {
el.focus();
}
}
return window.dash_clientside.no_update;
}
""",
Input('input', 'disabled')
)
@callback(
Output('spinner_div', 'children'),
Output('output', 'value'),
Input('input', 'value'),
prevent_initial_call=True,
running=[(Output('input', 'disabled'), True, False)]
)
def process(value: str):
sleep(1)
return '', value
if __name__ == '__main__':
app.run(debug=True)

Подробнее: https://stackoverflow.com/questions/799 ... re-enabled