reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Change behavior of switch, checkbox

Open Alek99 opened this issue 1 year ago β€’ 4 comments

class FormSwitchState(rx.State):
    form_data: dict = {}

    def handle_submit(self, form_data: dict):
        """Handle the form submit."""
        self.form_data = form_data


def switch_form_example():
    return rx.card(
        rx.vstack(
            rx.heading("Example Form"),
            rx.form.root(
                rx.hstack(
                    rx.switch(name="switch"),
                    rx.button("Submit", type="submit"),
                    width="100%",
                ),
                on_submit=FormSwitchState.handle_submit,
                reset_on_submit=True,
            ),
            rx.divider(),
            rx.hstack(
                rx.heading("Results:"),
                rx.badge(
                    FormSwitchState.form_data.to_string()
                ),
            ),
            align_items="left",
            width="100%",
        ),
        width="50%",
    )

Odd behaviour in switch I would expect it {"switch":"off"} or false but its empty in a form

https://github.com/user-attachments/assets/aa5eb99a-cf02-4304-bbc8-262f03a23d80

Alek99 avatar Oct 05 '24 00:10 Alek99

I would say it should set the form to True/False not off empty

Alek99 avatar Oct 05 '24 00:10 Alek99

same behavior for checkbox

Alek99 avatar Oct 05 '24 05:10 Alek99

Hello @Alek99 . Is this issue free ?

Rydzard avatar Oct 07 '24 10:10 Rydzard

is anyone still working on this issue?? can i try fixing it?

Ash-Jose avatar Nov 02 '25 18:11 Ash-Jose