跳至內容
選單
此問題已被標幟
1 回覆
4045 瀏覽次數

Is there a way to receive an event in odoo 17?

In my xml i have a button with a t-on-click="buttonOnclickPartner"

And this my my js file with my odoo.define:

odoo.define('sale_order_punch.geoloc', [], async function buttonOnclickPartner() { console.log('Button clicked');

});

This works, but i would like to do something similar to this code of odoo 15 in odoo 17:

odoo.define('sale_order_punch.geoloc', function (require){ 

​"use strict";

​var fromController = require('web.FormController');

​var fromRender = require('web.FormRenderer');

​var FormView = require('web.FormView');

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

​fromController.include({

​ ​_onButtonClicked: function (event) {

​ ​ ​console.log(event.data.record);

​ ​}

​});

});

頭像
捨棄
最佳答案

Hi,

To receive events in Odoo 17 using JavaScript, try using the below code,

XML:
<t t-on-click="(ev) => this._onButtonClicked(event)"/>

JS:
    /** @odoo-module */
    import { FormView } from "@web/views/form/form_view";
import { FormController } from "@web/views/form/form_controller";
    import { FormView } from "@web/views/form/form_view";
    import { useService } from "@web/core/utils/hooks";

patch(FormController.prototype, {
        setup(){
            super.setup();
            this.rpc = useService("rpc");
        },
        _onButtonClicked(event) {
            console.log(event);
        }
    });


Hope it helps

頭像
捨棄

are you really cybrosys? you are using patch without importing it. you import class that you never use. you pass wrong argument. and fatally, Odoo 17 prohibits directives using t-on-click yet you give this answer

相關帖文 回覆 瀏覽次數 活動
3
12月 23
30334
1
12月 19
9701
0
3月 17
8090
0
10月 18
3721
0
10月 18
7060