Hi everybody,

How do I make the “Submit” button become selectable only after copying all the texts?

this is my code


import streamlit as st
import pymongo

# Initialize connection.
client = pymongo.MongoClient(**st.secrets["mongo"])

db = client.streamlit
collection = db.test

# Using the "with" syntax
with st.form(key='my_form'):    
    first_name = st.text_input(label='Enter first name', key="first_name")
    last_name = st.text_input(label="Enter last name", key="last_name")
    submit_button = st.form_submit_button(label='Submit')

#st.write('Press submit to have your name printed below')

# if submit_button:
#     st.write(f'First name: {first_name}')
#     st.write(f'Last name: {last_name}')

document = {
    "name": f'{first_name}',
    "last_name": f'{last_name}'


Hi @Piero_Chiacchiaretta , I don’t think you can do this with forms. You can try this:

  1. Delete the line: with st.form(key=‘my_form’):
  2. After getting the value of first_name &
    last_name, do any validation of these inputs as required (eg. Checking if they both contain valid data, etc.)
  3. Change the line: submit_button = st.form_submit_button to submit_button = st.button and add the disabled parameter depending upon the result of step 2 above. You can refer this in the at.button documentation
  4. This way, only if valid data is entered, the button will be selectable. You can then proceed further as required


1 Like

thank you for the suggestion @Shawn_Pereira work. You now also how is possible clean the form after push the button ?

You can set the clear_on_submit parameter for st.form() to True. All widgets inside the form will be reset to their default values after the user presses the Submit button:

with st.form(key='my_form', clear_on_submit=True):  

Happy Streamlit-ing! :balloon:

Thanks, but with this method can’t make the “Submit” button become selectable only after insert all the texts in form.