Limit return values when filtering

Hi there, how are you doing? Got a question here on how to change the way the select box works. Let’s suppose I have this code:

values = [“ABC”, “ACB”, “ABB”, “BAB”, “CAB”]
options = st.sidebar.selectbox(“Name”, values)

When filtering the select box, I get as return all the options that contains the letters “A” + “B” in order, no matter what letters we have in the middle. So, the result is something like this:


When instead I would like to receive as return only “ABB” and “ABC”. Basically, I need the filter to treat the user input as chain and not as individual letters. Is there any way to change that behavior? I checked the documentation and the forum, but found nothing.

Thanks in advance!


Can you share your code???

Also I have nt gotten what you wanted to achieve

I shared my code at the beginning. Let’s make it an app:

import streamlit as st
values = [“ABC”, “ACB”, “ABB”, “BAB”, “CAB”]
options = st.sidebar.selectbox(“Name”, values)

When I type “AB” i get as return all the values that contains “A” and then “B”, no matter where they are placed. I need the code to give me just the values what STARTS with “AB” (only “ABC” and “ABB”)

1 Like

@georgi I got it. Will get back to you

Thanks :slight_smile:

Hi @georgi, I’m not sure if what you require is possible. st.selectbox has an on_change callback that is only triggered after the change to the selectbox is made, and not while it is being changed; hence, you would not be able to use something such as .startswith() to incrementally filter what you type in your selectbox, as you type it.

Nevertheless, let’s hope a more knowledgeable person comes along with a solution; meanwhile, you could petition Streamlit for this feature.