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;
|
background-color: #262730 !important;
|
||||||
border: 1px solid #4a4a4a !important;
|
border: 1px solid #4a4a4a !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hide the form submit button */
|
||||||
|
.stButton {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
""", unsafe_allow_html=True)
|
""", unsafe_allow_html=True)
|
||||||
|
|
||||||
@ -127,6 +132,10 @@ def main():
|
|||||||
st.session_state.tracker = TrackingLookup()
|
st.session_state.tracker = TrackingLookup()
|
||||||
if 'file_processed' not in st.session_state:
|
if 'file_processed' not in st.session_state:
|
||||||
st.session_state.file_processed = False
|
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
|
# File upload section
|
||||||
if not st.session_state.file_processed:
|
if not st.session_state.file_processed:
|
||||||
@ -143,8 +152,9 @@ def main():
|
|||||||
# Centered input with columns
|
# Centered input with columns
|
||||||
col1, col2, col3 = st.columns([1, 2, 1])
|
col1, col2, col3 = st.columns([1, 2, 1])
|
||||||
with col2:
|
with col2:
|
||||||
# Create a form to handle the Enter key properly
|
# Create a unique key for each form instance
|
||||||
with st.form(key='tracking_form'):
|
form_key = f'tracking_form_{st.session_state.form_count}'
|
||||||
|
with st.form(key=form_key):
|
||||||
tracking_input = st.text_input(
|
tracking_input = st.text_input(
|
||||||
"Tracking Number",
|
"Tracking Number",
|
||||||
label_visibility="collapsed",
|
label_visibility="collapsed",
|
||||||
@ -152,22 +162,39 @@ def main():
|
|||||||
)
|
)
|
||||||
submit_button = st.form_submit_button(label='Search', type='primary')
|
submit_button = st.form_submit_button(label='Search', type='primary')
|
||||||
|
|
||||||
# Process the form submission
|
if submit_button and tracking_input:
|
||||||
if submit_button or tracking_input: # This will catch both button clicks and Enter key
|
|
||||||
mailbag_no, sequence_no = st.session_state.tracker.lookup_tracking(tracking_input)
|
mailbag_no, sequence_no = st.session_state.tracker.lookup_tracking(tracking_input)
|
||||||
|
|
||||||
if mailbag_no:
|
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(
|
st.markdown(
|
||||||
f"""<div class="result-box">
|
f"""<div class="result-box">
|
||||||
<p><strong>Mail Bag No:</strong></p>
|
<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><strong>Sequence #:</strong></p>
|
||||||
<p>{sequence_no}</p>
|
<p>{st.session_state.last_result["sequence_no"]}</p>
|
||||||
</div>""",
|
</div>""",
|
||||||
unsafe_allow_html=True
|
unsafe_allow_html=True
|
||||||
)
|
)
|
||||||
else:
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user