auto clear input
This commit is contained in:
parent
e3a3ff47c9
commit
a676718615
41
app.py
41
app.py
@ -117,6 +117,11 @@ def main():
|
||||
background-color: #262730 !important;
|
||||
border: 1px solid #4a4a4a !important;
|
||||
}
|
||||
|
||||
/* Hide the form submit button */
|
||||
.stButton {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
""", unsafe_allow_html=True)
|
||||
|
||||
@ -127,6 +132,10 @@ def main():
|
||||
st.session_state.tracker = TrackingLookup()
|
||||
if 'file_processed' not in st.session_state:
|
||||
st.session_state.file_processed = False
|
||||
if 'last_result' not in st.session_state:
|
||||
st.session_state.last_result = None
|
||||
if 'form_count' not in st.session_state:
|
||||
st.session_state.form_count = 0
|
||||
|
||||
# File upload section
|
||||
if not st.session_state.file_processed:
|
||||
@ -143,8 +152,9 @@ def main():
|
||||
# Centered input with columns
|
||||
col1, col2, col3 = st.columns([1, 2, 1])
|
||||
with col2:
|
||||
# Create a form to handle the Enter key properly
|
||||
with st.form(key='tracking_form'):
|
||||
# Create a unique key for each form instance
|
||||
form_key = f'tracking_form_{st.session_state.form_count}'
|
||||
with st.form(key=form_key):
|
||||
tracking_input = st.text_input(
|
||||
"Tracking Number",
|
||||
label_visibility="collapsed",
|
||||
@ -152,22 +162,39 @@ def main():
|
||||
)
|
||||
submit_button = st.form_submit_button(label='Search', type='primary')
|
||||
|
||||
# Process the form submission
|
||||
if submit_button or tracking_input: # This will catch both button clicks and Enter key
|
||||
if submit_button and tracking_input:
|
||||
mailbag_no, sequence_no = st.session_state.tracker.lookup_tracking(tracking_input)
|
||||
|
||||
if mailbag_no:
|
||||
st.session_state.last_result = {
|
||||
"mailbag_no": mailbag_no,
|
||||
"sequence_no": sequence_no,
|
||||
"found": True
|
||||
}
|
||||
else:
|
||||
st.session_state.last_result = {
|
||||
"found": False,
|
||||
"tracking": tracking_input
|
||||
}
|
||||
|
||||
# Increment form count to create a new form instance
|
||||
st.session_state.form_count += 1
|
||||
st.rerun()
|
||||
|
||||
# Display results if they exist
|
||||
if st.session_state.last_result:
|
||||
if st.session_state.last_result["found"]:
|
||||
st.markdown(
|
||||
f"""<div class="result-box">
|
||||
<p><strong>Mail Bag No:</strong></p>
|
||||
<p>{mailbag_no}</p>
|
||||
<p>{st.session_state.last_result["mailbag_no"]}</p>
|
||||
<p><strong>Sequence #:</strong></p>
|
||||
<p>{sequence_no}</p>
|
||||
<p>{st.session_state.last_result["sequence_no"]}</p>
|
||||
</div>""",
|
||||
unsafe_allow_html=True
|
||||
)
|
||||
else:
|
||||
st.warning("❌ Tracking number not found in the uploaded data")
|
||||
st.warning(f"❌ Tracking number not found in the uploaded data")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user