Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
6 Відповіді
20419 Переглядів

How do I execute javascript in qweb? I read through the documentation and it mentioned a t-js tag. But I can't get it to work.

I have created a table in a qweb report. But if the table cannot fully fit onto one page, I need to insert a page-break before the table. Therefore, it becomes a conditional page-break. For this I need to obtain the height of the table. One technique is through javascript:

var table = document.getElementById("tableId");

alert(table.offsetHeight);

I need to execute these lines in QWeb, and then I also need to pass the value of the offset height  from javascript to a qweb variable. Is this possible?

I find QWeb to be a powerful tool for dynamic HTML generation, but sadly, the documentation is very poor.

Аватар
Відмінити

I would also love to know how to accomplish this. I believe javascript can be the answer to my question posted here: https://www.odoo.com/forum/help-1/question/qweb-drop-trailing-0s-after-decimal-73314

I've just bumped into the same issue. Per the documentation, it is clear that placing "t-js" node inside the template does exactly what you require (https://www.odoo.com/documentation/8.0/reference/qweb.html). However, as I try it, it just 'prints' the javascript code into the pdf report (¿?), as if it were any regular html tag. Have any of you had any luck with this matter?

Did you ever solve this?

Найкраща відповідь

i solved it with <scriptlanguage="javascript"type="text/javascript">

Аватар
Відмінити
Найкраща відповідь

I am also trying to find a solution for this, can anyone help ?

Аватар
Відмінити
Найкраща відповідь

In the Odoo Studio : studio_customization where you add the <xpath> elements, inside /t or /t/t
 (<xpath expr="/t/t" position="inside">)
you can ad a script tag just as in html
<script>

//Javascript code

</script>
You can access the DOM and do many other things this way

Аватар
Відмінити
Найкраща відповідь

guys, did you solve this? if not, you go like this:

<t t-jquery="[t-set*='columns_count']" t-operation="replace">
<t t-js="ctx">
var table = document.getElementById("tableId");

                        alert(table.offsetHeight);

</t>
<t t-if="show_order_numbers">
</t>
I have put t-jquery just that you know that t-js must go in there, but the value of t-jquery depends where you want to insert your js code.....
Аватар
Відмінити
Найкраща відповідь

Same issue, did anyone manage to solve this ?

Аватар
Відмінити
Найкраща відповідь


Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
груд. 15
4245
Set report orientation Вирішено
1
бер. 15
14319
0
бер. 15
3382
3
бер. 15
17772
2
черв. 25
4273