Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1242 มุมมอง

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



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Onboarding Icon on odoo 18 แก้ไขแล้ว
2
เม.ย. 25
2039
0
ม.ค. 25
1136
1
ธ.ค. 24
1853
1
พ.ย. 24
2240
When is Odoo 18 going to be available? แก้ไขแล้ว
1
ต.ค. 24
7048