Multiple "roles"

Can we be allowed to add multiple “roles” to a component?

I find myself writing lots of css variations when all I really want to do is to compound some features sometimes.

An aside, but I think “role” is the wrong thing to call that property, at least for what it is currently used for. I think it should be called “custom classes” or something like that.

7 Likes

+1 for a better name, “Additional classes” comes to mind as well.

+1 for making available “roles” (or classes) displayed as a list of checkboxes, enabling selection of one or many in any combination

1 Like

or something like this “lozenge” system : Multi Select Drop Down? - #42

1 Like

Yes, that would be great!

I already +1’d the idea, but want to express official support. I never quite understood why we could only have one role, when the roles are basically CSS classes. It’d be great to be able to tick off all the ones that should apply to a particular component.

1 Like

Hi @david.wylie,

You can apply multiple roles to a component from code. For example:

self.label_1.role = ['blue-text', 'bold-text', 'green-background']
8 Likes

Yay!
Whaaat?
Since when?
Is this something new? I just searched in the documentation and I haven’t found any mention of this.

(I just assumed I’d missed it - maybe I didn’t?)

But yes - yay indeed :slight_smile:

@stefano.menci it’s currently in Beta which is why it isn’t in the docs - we wanted to see if it’s something that people want, and clearly it is! :slight_smile:

1 Like

Indeed. This will allow to decrease the role proliferation that we have now.

Does self.label_1.role.remove('blue-text') work?

No, it won’t - properties are triggered by attribute setting operations, so you’ll want something like:

self.label_1.role = [r for r in self.label_1.role if r != 'blue-text']

Yes, please - that would be great :slight_smile: . Of course, we can now achieve a similar result with addClass on “JQuery-references” of Anvil components - but this only shows at run-time (and requires a bit more code than the elegant Roles).