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

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ธ.ค. 23
30334
Odoo 12 JS custom_events แก้ไขแล้ว
1
ธ.ค. 19
9698
0
มี.ค. 17
8089
0
ต.ค. 18
3719
0
ต.ค. 18
7058