Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
786 Vistas

is there a way to do the following ?

in a standard listview i want to add a css class ... or another way to style it beside the 

                <field name="data_provider_type"

                       string="Provider"

                       widget="badge"

                       class="o_badge_{{data_provider_type}}"/>

#to result in something like

<div name="data_provider_type" class="o_field_widget o_required_modifier o_field_badge o_badge_Foo"><span class="badge rounded-pill text-bg-300">Foo</span></div>

Avatar
Descartar
Mejor respuesta

I'd say it highly depends on what you'd like to achieve with o_badge_Foo and what you want to cover.

Some options are:

Using decoration-ALERTTYPE attributes (works nicely when common bootstrap alert types are applicable):

<field name="data_provider_type" 
widget="badge"
decoration-info="data_provider_type == 'a'"
decoration-warning="data_provider_type == 'b'"
decoration-danger="data_provider_type == 'c'"
decoration-success="data_provider_type == 'd'"/>


Using simple invisible attributes (works nicely, when there is a limited number of different classes to be applied):

<field name="data_provider_type" widget="badge" class="abc" invisible="data_provider_type != 'a'"/>
<field name="data_provider_type" widget="badge" class="xyz" invisible="data_provider_type != 'b'"/>


Using a custom widget:

See https://www.odoo.com/documentation/18.0/developer/howtos/javascript_field.html

(or any other core widget: https://www.odoo.com/documentation/18.0/applications/studio/fields.html)


Also, you maybe could use a different field type to begin with - i.e. a Many2many. This would allow you to utilize the many2many_tags widget that is rendered similarly to a badge, but allows for and additional options attribute to define what field to fetch the color for that particular tag from:

<field name="data_provider_type_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>



Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
abr 25
1381
0
ene 25
804
1
dic 24
1449
1
nov 24
1748
1
oct 24
6235