I have a form that updates an SQL database when a ‘submit’ button is pressed. If any of the form inputs are missing, submission will be disallowed until the user fills in all the inputs. The problem, however, is after the submit button is pressed a single time, regardless of success/failure, when the form is filled again it automatically submits without pressing the “submit” button, and this behavior persists until the page is refreshed. Can anyone see what I’m missing?
@callback(
Output('output-provider', 'children'),
Output('lot-number','value'),
Output('production-date','value'),
Output('membrane-lot','value'),
Input('commit-to-database-button', 'submit_n_clicks'),
Input('lot-number','value'),
Input('production-date','value'),
Input('membrane-lot','value'),
)
def update_prod_database(submit_n_clicks, lot, prod_date, memb_lot, memb_lot_cut):
if not submit_n_clicks:
return '', no_update, no_update, no_update
else:
engine = connect_mariadb()
var_list = [lot, prod_date, memb_lot, memb_lot_cut]
# Generate True/False values for each input on form.
bool_list = [(x is not None and x != '') for x in var_list]
# Sums bool values in bool_list. If any inputs are missing, sum will be less than 4
if sum(bool_list) == 4:
df = pd.DataFrame(
{
'lot': [lot],
'date_of_production': [prod_date],
'membrane_lot': [memb_lot],
'membrane_lot_cut': [memb_lot_cut]
}
)
df.to_sql(
name="membrane_spray_prod_results",
con=engine,
if_exists="append",
index=False)
return "Submission successful. You may close this form or enter new values.", '', '', '', ''
else:
return "Submission failed. Please double-check values and try again.", no_update, no_update, no_update, no_update,