跳至內容
選單
此問題已被標幟
1 回覆
11005 瀏覽次數

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?

頭像
捨棄
最佳答案

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=""
頭像
捨棄
作者

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.

作者

Thanks for your answer Ray!

相關帖文 回覆 瀏覽次數 活動
2
10月 21
4289
1
9月 21
2504
2
6月 21
4522
1
7月 25
2277
2
7月 25
7751