Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
11099 Lượt xem

I am trying to do some styling on a project kanban tile based on a selection field I added to the task. Here is a snippet of my attempt.


<xpath expr="//div[@class='oe_kanban_bottom_left']" position="replace"/>

          <!-- Color border -->

          <xpath expr="//templates/t/div" position="attributes">

            <t t-if="record.order_type.raw_value == 'store'">

              <attribute name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: steelblue;</attribute>

            </t>

            <t t-else-if="record.order_type.raw_value == 'curb'">

              <attribute name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: firebrick;</attribute>

            </t>

            <t t-else-if="record.order_type.raw_value == 'delivery'">

              <attribute name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: mediumseagreen;</attribute>

            </t>

          </xpath>

This results in only the last attribute getting used regardless of the value of order_type. I think this is because the <t> elements are just getting ignored. I have also tried to use the <t t-esc> to embed the color text in the value, but that resulted in outputting an empty string. I also tried attaching t-if attributes on the <attribute> tag itself. None of these things have worked.


Any suggestions on how to apply a style based on the value of the task?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

EDIT:

I took a closer look at what you are wanting to do.

For your specific example, I was able to get this:



I created a custom selection field that stored the HTML codes of the colors as the Value:



Then used this syntax for changing the style attribute:

<attribute name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: {{record.x_order_type.raw_value or 'white'}};</attribute> 

Note that you don't actually need the t-attf- prefix when you are not using substitution to compute attributes on-the-fly - see https://www.odoo.com/documentation/14.0/developer/reference/qweb.html#attributes



Original Answer:


The supported t- directives for IF/THEN/ELSE are:

t-if
t-elif
t-else

t-else-if is not supported.


See a code example at https://github.com/odoo/odoo/blob/14.0/addons/product/report/product_packaging.xml#L31

<img alt="Barcode" t-if="len(packaging.barcode) == 13"
<img alt="Barcode" t-elif="len(packaging.barcode) == 8"
<img alt="Barcode" t-else=""
Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks for the correction on my syntax, but this unfortunately didn't solve my problem. The third attribute element is always applied, regardless of the value of the order_type variable. Here is my updated xml: (Yes I know there are redundant t-if's here)

<t t-if="record.order_type.raw_value == 'store'">

<attribute t-if="record.order_type.raw_value == 'store'" name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: steelblue;</attribute>

</t>

<t t-elif="record.order_type.raw_value == 'curb'">

<attribute t-if="record.order_type.raw_value == 'curb'" name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: firebrick;</attribute>

</t>

<t t-elif="record.order_type.raw_value == 'delivery'">

<attribute t-if="record.order_type.raw_value == 'delivery'" name="t-attf-style">margin-bottom: 10px; border-width: 5px; border-color: mediumseagreen;</attribute>

</t>

See the EDIT to my answer.

Tác giả

Thanks for your answer Ray!

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 10 21
4387
1
thg 9 21
2598
2
thg 6 21
4647
1
thg 7 25
2432
2
thg 7 25
7897