Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4546 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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,



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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!')
​}
}


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 24
4006
1
thg 6 24
3040
0
thg 12 23
1618
2
thg 7 24
4795
2
thg 5 24
1610