Can I add to. a selectbox an "other" option, where the user can add his own answer?

I want to add to a selectbox an “other” option, where the user can add his own answer, I can’t find how, who can help?
fyi - I did see this awesome streamlit-tags option, but it’s not what I want, I want a drop down list with the option to write your own option…

Hi @Efrat_Garber_Aran , you will need to add a textbox for the user to type in the option not already present in the selectbox.

If the textbox variable contains new text when your program is run, add it to the options of the selectbox; if not, the user can still select options from the selectbox.

Cheers

1 Like

I’d condition a st.text_input to one of the possible options in the st.selectbox, like this:

selectbox

import streamlit as st

# Create selectbox
options = [f"Option #{i}" for i in range(3)] + ["Another option..."]
selection = st.selectbox("Select option", options=options)

# Create text input for user entry
if selection == "Another option...": 
    otherOption = st.text_input("Enter your other option...")

# Just to show the selected option
if selection != "Another option...":
    st.info(f":white_check_mark: The selected option is {selection} ")
else: 
    st.info(f":white_check_mark: The written option is {otherOption} ")