跳至内容
菜单
此问题已终结
1 回复
1007 查看

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>

形象
丢弃
最佳答案

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'}"/>



形象
丢弃
相关帖文 回复 查看 活动
2
4月 25
1716
0
1月 25
986
1
12月 24
1628
1
11月 24
2010
1
10月 24
6742