Toogle Switch not visible when expected

Hi everyone

What I’m trying to do:

Have a toggle switch visible as expected based on the visibility status of its container (called filter_option_container)

It’s the toggle switch from here: Toggle Switch and Progress Bar

What I’ve tried and what’s not working:

I’ve tried adding the toggle switch as a component in the container, setting the container to hidden by default, and then using a button with code to make the container visible when the button is clicked. The button click works, and the container becomes visible with all its other components EXCEPT the toggle switch, which, althrough set to visible, cannot be seen. It then becomes visible when I click on its position.

Code Sample (the normal code for hiding and showing a container based on a button click):

  def filter_expand_button_click(self, **event_args):
    if self.filter_option_container.visible == False:
      self.filter_option_container.visible = True
      self.filter_expand_button.text = 'Hide'
    else:
      self.filter_option_container.visible = False
      self.filter_expand_button.text = 'Set filters'
    pass

The toggle switch will be a lot nicer for users to use than a checkbox so I am hoping not to need to default to that. Any help would be much appreciated.

Thanks,

Richard

It would be great to have a clone link to help debug this issue.

One that just highlights the unexpected behaviour would be ideal.

And related post on how to include the dependency with the clone:

1 Like

Thanks for the pointer.

I’ve made this clone which isolates the issue:
https://anvil.works/build#clone:WYC3EKXQE2J323OJ=RUKMUIG7PY3LHY2ISEONOGRW

Confirming this is a bug

As a patch if you go into your version of toggle switch and add update as the handler for the canvas reset event it should work

Screenshot 2021-06-19 at 21.32.38

You may have already seen but anvil-extras includes an alternative switch and slider component that may be useful for you.

1 Like

Great - the patch worked and my app is now successfully using the toggle switch. Thanks!

1 Like