Hello! I just joined Plotly Forum and am still learning my way around Dash.
I am building a data entry system with 3 input boxes and a submit button. Entered data compares with a backend database and returns a “PASS/FAIL” alert to the user. Data is entered by using a bar code scanner. Everything is working as intended.
However, to improve the ease of use, I’d like the cursor to move to the next input box as soon as the current box is filled. I’d also like the page to automatically submit and clear all boxes as soon as the last box is filled but the alert should stay.
Here is what I have currently. I’m also open to any suggestions on overall improvement of my code. Thanks!
def update_database(star, serial, weight, andon):
sheet.append([datetime.now(), A, B, C, andon])
raw.save(r'test.xlsx')
def compare_tol(A, B, C):
if star is not '':
compare_group = df_main.loc[star, 'Group']
if float(C) > float(df_groups.loc[compare_group, 'Upper']) or \
float(C) < float(df_groups.loc[compare_group, 'Lower']):
andon = 'FAIL'
else:
andon = 'PASS'
else:
andon = '...'
update_database(A, B, C, andon)
return andon
def which_entry(label):
layout = html.Div([
dcc.Input(
id=label,
placeholder=f' {label}...',
type='text',
value=''
)
], style={'padding': '5px 5px'})
return layout
app.layout = html.Div([
html.Div([
html.Img(src='http://xxx.png',
width='250px')
]),
html.Div([
html.Div([
html.H3('Scan A'),
]),
which_entry('A'),
html.Div([
html.H3('Scan B')
]),
which_entry('B'),
html.Div([
html.H3('Enter C')
]),
which_entry('C'),
], style={'text-align': 'center'}),
html.Div([
dbc.Button('Submit', id='button', color='primary')
], style={'text-align': 'center',
'width': '250px'}),
html.Div([
dbc.Alert(id='andon', color='secondary')
], style={'text-align': 'center',
'width': '250px',
'padding': '5px 5px'})
], style={'width': '250px'})
@app.callback(
Output('andon', 'children'),
[
Input('button', 'n_clicks')
],
[
State('A', 'value'),
State('B', 'value'),
State('C', 'value'),
]
)
def output_text(n_clicks, A, B, C):
return compare_tol(A, B, C)
@app.callback(
Output('andon', 'color'),
[
Input('button', 'n_clicks'),
Input('andon', 'children')
],
)
def andon_color(n_clicks, andon):
if n_clicks:
if andon == 'PASS':
return 'success'
elif andon == 'FAIL':
return 'warning'
else:
return 'secondary'