Skip to Content
Menu
This question has been flagged
1 Reply
4022 Views

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);

​ ​}

​});

});

Avatar
Discard
Best Answer

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

Avatar
Discard

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 Replies Views Activity
3
Dec 23
30325
1
Dec 19
9692
0
Mar 17
8080
0
Oct 18
3709
0
Oct 18
7053