Skip to Content
Menu
This question has been flagged
2 Replies
11935 Views

I want to register onclick event for a button. Please help

odoo.define('test.payment_checkout', require => {
'use strict';

const core = require('web.core');
const Dialog = require('web.Dialog');

const _t = core._t;
console.log('test.payment_checkout');
return {
start: function () {
$('#test').click(function () {
console.log("TEST")
});
},

}
})

The file is loaded because I can see the console.log in browser's console. But the button didn't do anything

Avatar
Discard
Best Answer

Hi,

You can try like this example.

odoo.define('test.shop_cart', function (require) {
"use strict";

var rpc = require('web.rpc');

$(document).on('click', '#test_button', function(){

     console.log("test")
 });
});

Regards

Avatar
Discard

Can you post the full code, I try to call JavaScript from button click on a form but didn't get any result.

Author Best Answer

I figured it out

odoo.define('test.shop_cart', function (require) {
"use strict";

var rpc = require('web.rpc');

$(document).on('click', '#test_button', function () {

console.log("test")
return rpc.query({
model: 'my_module.test',
method: 'get_sale_order',
args: [""],
})
.then(function (result) {
console.log(result)
});
});
});

def get_sale_order(self):
return "TEST"


Avatar
Discard
Related Posts Replies Views Activity
2
Apr 22
2792
1
Apr 22
2018
9
Jun 24
26804
1
Nov 23
8232
0
Nov 23
927