Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
4316 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer

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

Gerelateerde posts Antwoorden Weergaven Activiteit
3
dec. 23
30429
1
dec. 19
9812
0
mrt. 17
8270
0
okt. 18
3852
0
okt. 18
7172