Skip to content

on_change does not work #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
quying opened this issue Sep 4, 2024 · 4 comments
Open

on_change does not work #68

quying opened this issue Sep 4, 2024 · 4 comments

Comments

@quying
Copy link

quying commented Sep 4, 2024

When I set on_change callback, it's not called.

def switch_session():
    st.write(f'session changed: {st.session_state.new_session}')

menu_items = [sid for sid in sorted_ids]
item = sac.menu(menu_items, open_all=True, format_func=format_session, on_change=switch_session, key="new_session")

Streamlit==1.36.0
streamlit_antd_components==0.3.2

@Socvest
Copy link

Socvest commented Sep 10, 2024

@quying I have built a patch reflecting changes in v. 1.36.0 here.

@maxronk
Copy link

maxronk commented Sep 15, 2024

I get an error as well - TypeError: ButtonsItem.init() got an unexpected keyword argument 'on_change'

    # Function to add a new tab
    def add_tab():
        st.session_state.num_tabs += 1

    # Function to remove a tab
    def remove_tab():
        if st.session_state.num_tabs > 1:
            st.session_state.num_tabs -= 1

    sac.buttons([
    sac.ButtonsItem(label="Add Tab", on_change=add_tab),
    sac.ButtonsItem(label="Remove Tab", on_change=remove_tab, disabled=st.session_state.num_tabs == 1),
    ],
    )

Name: streamlit
Version: 1.38.0

Name: streamlit-antd-components
Version: 0.3.2

@maggie1121
Copy link

maggie1121 commented Oct 14, 2024

sac.buttons callback args is still broken.

    def callback(*args, **kwargs):
        print(f"callback args: {args}")

    def test():
        key = uri + f"_{name}_buttons"
        print(f"key: {key}")
        sac.buttons(
            [sac.ButtonsItem(uri) for uri in uris],
            index=None,
            size='xs',
            key=key,
            on_change=callback, args=(key,)
        )

The above code is broken with an upgrade if streamlit1.36.0, the callback args print out empty tuple: ()

@luminoso
Copy link

@maggie1121 in the meanwhile did you found any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants