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

How to make connection of javascript with odoo?

For example:- I declared a button in xml and written a function in javascript then how to call that function on xml button.


My code is :-

xml button declaration:-

<footer>
<button name="button" onclick="updatetxt(fun)" string="ok"/>
</footer>
         
     
     
javascript and xml connection code:-
     
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="Javascript_Test" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<!-- <link rel="stylesheet" href="/web/static/lib/bootstrap/css/bootstrap.css"/> -->
<!-- <link rel="import" href="//static/src/timesheet.html"/> -->
<script type="text/javascript" src="/Javascript_Test/static/src/js/document.js"/>
</xpath>
</template>

</data>
</openerp>
    
javascript code:-
    
function updatetxt()
{
alert("hello");
}
     
manifeast file:-
     
'data': [
'views/views.xml',
'views/java_script.xml',
],

'js': [
'static/src/js/document.js'
],
 
     
So how to declare javascript on button with xml in odoo?
อวตาร
ละทิ้ง

Hi, I've changed your question title from " How to integrate js with Odoo" to "how to call javascript function on button with xml in odoo?".

คำตอบที่ดีที่สุด

Hi Gautam,

You can give a class for your button in xml

<button name="button" class="your_class" string="ok"/>

then in js give any click event for that class

events: {
"click .your_class": "your_function",
},
your_function: function () {
console.log('Button Clicked')
},


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

Hello mohammed, i tried the above solution but didn't work. Is there any other solution for this?

This should work. Are you sure your js is working properly. can you share your code.

ผู้เขียน

onclick: {

"click .txt_js": "updatetxt",

},

updatetxt: function () {

console.log('Button Clicked')

},

this is my code. can you suggest if there is any error?

how did you give onclick. I think onclick works like that only if you extended formview.

ผู้เขียน

What should i use in place of onclick if i have to work on a button?

guys how to do this in odoo 12

Hi gautam,have u arrived any solution for this??

Related Posts ตอบกลับ มุมมอง กิจกรรม
Display field value using javascript แก้ไขแล้ว
1
ก.ย. 21
8428
1
มิ.ย. 23
3399
Get data from JS file to XML file แก้ไขแล้ว
1
ส.ค. 20
8820
2
มิ.ย. 20
3857
1
ก.ย. 18
106