Seeker
Seeker

Reputation: 1268

Odoo QWEB: show an element only if it has any length

I have a note field that I want to show in an Odoo report, but only if it has any length.

I tried this without success:

<t t-if="len(o.note) > 0"    
  <div t-field="o.note" style="border:1px solid black;"></div>
</t>

Getting errors. What is the right way of doing this? Thx in advance. Using Odoo 16.0

Upvotes: 0

Views: 227

Answers (2)

Dheeraj Pandey
Dheeraj Pandey

Reputation: 1

You can try this.

<t t-if="o.note">
    <div style="border: 1px solid black;">
        <t t-esc="o.note"/>
    </div>
</t>

Upvotes: 0

Yassir Irfan
Yassir Irfan

Reputation: 1210

Try this approach; if the field contains no values, Odoo will declare it False, so you won't actually need to check the length.

<t t-if="o.note"    
  <div t-field="o.note" style="border:1px solid black;"></div>
</t>

Upvotes: 2

Related Questions