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

Hi everybody

How can I check the state of a checkbox inside a t-foreach of a QWeb report?
The idea is to print the name and number from the same model if the checkbox is checked. 
So far I can loop over the records and I can print out the name & number but now my question is.. how can I write a t-if that checks if the checkbox is checked or not?

Code:

 <t t-if="company.bank_ids" t-foreach="company.bank_ids" t-as="item">
                   <!--This line should check if the checkbox is checked or not..-->
                        <t t-if="item.footer=='True'">
                                <span t-field="item.bank_name"/>
                                <span t-field="item.acc_number"/>
                        </t>
                </t>

If I remove the t-if <item.footer=='True'"> I'll get every line printed. How can I only print the values of the record that has a checkbox set to true?

With kind regards
Yenthe

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Yenthe,

Condition you are using is logically wrong. You have given your condition value as a string ('True') not as boolean value.

You can use conditional statements same as python.

It should work like this:

<t t-if="item.footer">
    <span t-field="item.bank_name"/>
    <span t-field="item.acc_number"/>
</t>

If you want to check for False condition:

<t t-if="not item.footer">

อวตาร
ละทิ้ง
ผู้เขียน

Thanks Sudhir this works like a charm! So what if I would want all non-checked checkboxes? I tried with and but none of those seem to work. Could you add that in the answer too? Guess this could help others too. Anyways, I've accepted and upvoted the answer. Thanks!

ผู้เขียน

They both work perfect. Thank you for adding the False condition Sudhir!

Related Posts ตอบกลับ มุมมอง กิจกรรม
How to add custom fonts to QWeb reports? แก้ไขแล้ว
6
ม.ค. 24
68366
2
ก.ย. 24
1996
1
มี.ค. 22
7535
How do i create report in Qweb? แก้ไขแล้ว
5
ส.ค. 19
46581
4
มิ.ย. 18
20152