Odoo javascript onclick event

烈酒焚心 提交于 2019-12-08 03:30:56

问题


Is it possible create my own button and this button click call javascript function? Like simple onclick javascript method?

If the answer is yes, how can I do that?

I want to use "Add an item" button or create my own button that calls the same function like I click on "Add an item" button.


回答1:


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

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

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();
    },
});
});

i have posed this type of question, i got this solution this answer working partially. please refer this link how to write events for formview inside header buttons? odoo 10



来源:https://stackoverflow.com/questions/45555023/odoo-javascript-onclick-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!