I have two input components, one selectbox and one text-input.
The user can either select an item from the selectbox (variable “options”) or input his own string into the text-input (variable “search_string”).
This string will be assigned to a third variable “search_item”.
However always the first (upper) input field gets used for “search_item”. I want it to use the last changed input.
How can I fix it?
Here’s my code:
search_item = None
options = st.selectbox(
'Select a predefined thematic:',
('', 'Rare Earth', 'Autonomous Driving', 'Semiconductor', 'Wind Power', 'Metaverse', 'Orange Juice'),
index=0,)
search_string = st.text_input('Or create your own thematic search:')
if options:
print('options selected: ', options)
search_item = normalize('NFKD', options.lower()).encode('ascii', 'ignore').decode('ascii').strip()
elif search_string:
print('search_string selected: ', search_string)
search_item = normalize('NFKD', search_string.lower()).encode('ascii', 'ignore').decode('ascii').strip()