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

Hi i am trying to call js function from odoo16 Button but i could not get success:

here is xml code:
id="view_sale_order_form_inherit" model="ir.ui.view">
name="name">sale.order
name="model">sale.order
name="inherit_id" ref="sale.view_order_form"/>
name="arch" type="xml">

expr="//form" position="attributes">
name="js_class">sale_order_blog


expr="//header" position="inside">

href="#" t-on-click="_MoreOptions">
class="fa fa-ellipsis-v"
style="font-size:24px">








and js code 

/** @odoo-module **/
import { FormRenderer } from "@web/views/form/form_renderer";
const Dialog = require('web.Dialog');
export class ComSaleOrderRender extends FormRenderer {
setup() {
super.setup();
}
_MoreOptions(){
console.log('Hello World!')
}
}


when click on button it gives this error:


can anybody help me on call js function from click on a button in odoo16
Thank in advance

Avatar
Discard
Best Answer

Hi,

1. You can add the following templates 

<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-extend="FormView.buttons" t-name="button_near_create.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
           <button type="button" class="btn btn-primary open_wizard_action">
               Open Wizard
           </button>
       </t>
   </t>
</templates>


2. Add following js code
/** @odoo-module **/
     import FormController from 'web.FormController';
    import FormView from 'web.FormView';
    import viewRegistry from 'web.view_registry';

    var SaleFormController = FormController.extend({  buttons_template: 'button_near_create.buttons',
   events: _.extend({}, ListController.prototype.events, {
       'click .open_wizard_action': '_MoreOptions',
   }),
   _MoreOptions: function () {
     console.log('Hello World!')
   }
});
var SFormView = FormView.extend({
        config: _.extend({}, FormView.prototype.config, {
            Controller: CrmFormController,
        }),
    });

    viewRegistry.add('sale_order_blog', CrmFormView);

    export default {
        CrmFormController: CrmFormController,
        CrmFormView: CrmFormView,
    };

Hope it helps,



Avatar
Discard
Best Answer

in my experience, odoo 16 have already custom the button tag. personally I'm using div tag
in xml


div t-on-click="_MoreOptions" . button ./div


in js


export class ComSaleOrderRender extends FormRenderer { ​setup() {
​super.setup();
​}
​_MoreOptions(){
​console.log('Hello World!')
​}
}


Avatar
Discard
Related Posts Replies Views Activity
1
Jun 24
3312
1
Jun 24
2451
0
Dec 23
1285
2
Jul 24
4151
2
May 24
1174