The use case is as follows:
I have a repeating panel.
I’m using this repeating panel to craft
This repeating panel’s template_row has 3 cards each with 4 buttons, for a total of 12 buttons.
I’d like to add a new role for all of the said 12 buttons, like I read that is possible via the client-code interface: Multiple "roles"
This role will make them have a fixed width so everything is symetrical.
I’d like to do something like:
buttonsList = self.elements.buttons
for button in buttonsList:
if type(button.role) == type([])
button.role += ['width260']
else:
button.role = [button.role, 'width260']
Have you got a clone or a minimal example you can share?
You should be able to do it by creating list based on get_components()
and then do what ever you want from there. You can create a list from that if you require it but to change the roles the below should work.
for card in self.repeating_panel_1.get_components():
card.button.role = 'primary-color' # or which ever role you need
See sample app below which only addresses one button but the mechanics will be the same. Let me know if you get stuck.
https://anvil.works/build#clone:M4RBHIK2TLU3H6SJ=KQRI3RFBKUS2S4VTXFWZHB4L
1 Like
There may be a better way to address this though if the width is all you are changing. Anvil is pretty good at responding to screen sizes, I wonder if there is a setting we could change so this code is not required.
Have you got an exmple?
Sometimes anvil breaks the text line if the button’s space gets too tight.
It would be usefull to forbid this behaviour somehow.
The only thing I thought of was making it have a lower threshold for the width property.
But I would like to set it for many buttons at once, having to do it one at a time, takes time.
Which brought my mind to tags.
Maybe I can select objects based on defined tags.
I was going to try it on an image set.
I realized during the attempt that I can’t define the tag property using the UI.