如何在标题按钮内写入formview事件? odoo 10 [英] how to write events for formview inside header buttons? odoo 10

查看:331
本文介绍了如何在标题按钮内写入formview事件? odoo 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在odoo10社区尝试过这段代码但没有工作,我的错是什么?

I have tried this code in odoo10 community but not working, what is my fault?

或者有人能指导我怎么做吗?

Or Can anyone guide me how to do it?

    openerp.module_name= function (instance) {

            var _t = instance.web._t, QWeb = instance.web.qweb;

                instance.web.FormView = instance.web.FormView.include({
                init: function() {
                        this._super.apply(this, arguments);
                        console.log("test"+this.getParent().dataset.model); 
                    },
                    events: {
                       'click #target': 'button_clicked',
                    },
                    button_clicked : function(ev) { 
                        console.log("test333555555");
                        ev.preventDefault();
                        ev.stopPropagation();
                        console.log("test 333333333333");
                    });         

                 },

            });
};


推荐答案

首先创建按钮,您想要创建一些按钮修改。

First Create button where ever you want to create with some modifications.

<button string="Click" custom="click"/>

然后创建一个包含以下代码的 JS 文件。

Then create one JS file that will contain following code.

odoo.define('YOUR_MODULE.FILENAME', function (require) {
"use strict";

var form_widget = require('web.form_widgets');
var core = require('web.core');
var _t = core._t;
var QWeb = core.qweb;

form_widget.WidgetButton.include({
    on_click: function() {
         if(this.node.attrs.custom === "click"){

            // YOUR CODE

            return;
         }
         this._super();
    },
});
});

将此JS添加到XML

<?xml version="1.0" encoding="utf-8"?>
<odoo>
        <template id="assets" inherit_id="web.assets_backend">
          <xpath expr="." position="inside">
              <script type="text/javascript" src="/YOURMODULE/static/js/FILENAME.js"></script>
          </xpath>
        </template>
</odoo>

在__manifest中添加xml __。py

{
...
...
'data': [
        ...
        'views/above_xml_filename.xml',
    ],
....
}

我希望这对你有用。

这篇关于如何在标题按钮内写入formview事件? odoo 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆