This question has been flagged
2 Replies
26818 Views

I have a button named  "click" on a form, i want to catch the 'onclick' action in order to run a JS function.

I followed this link so it can work, it did not

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-customize-the-onclick-javascript-action-of-an-edit-button-odoo-10-125253

here are the errors i got :

web.assets_common.js:3776 warning: Some modules could not be started
Missing dependencies:    ["web.form_widgets"]
Non loaded modules:      ["upload_multi_attachments.attachs"]

My form code (xml):

                  <div class="o_row">
                            <button string="Click" id ="adel" class="o_adel" name="click" type="object" custom="click"/>
                            <br/>
                  </div>

My button code (JS) :

odoo.define('upload_multi_attachments.attachs', function (require) {
"use strict";
var Widget = require('web.Widget');
var core = require('web.core');
var _t = core._t;
var QWeb = core.qweb;
var form_widget = require('web.form_widgets');
form_widget.WidgetButton.include({
    on_click: function() {
         if(this.node.attrs.custom === "click"){
         return;
         }
         this._super();
    },
});
});

                   


Avatar
Discard
Best Answer

var form_widget = require('web.FormRenderer');

     form_widget.include({

        _addOnClickAction: function ($el, node) {

            var self = this;

            $el.click(function () {

                //MY CODE

                if(node.attrs.id === "darkroom-save")

                        darkroomBut.darkroom.plugins.crop.cropCurrentZone(true);

                  //just code old may use super

                self.trigger_up('button_clicked', {

                    attrs: node.attrs,

                    record: self.state,

                });

            });

        },

    });



OR on 09.10.2018 new solution

var FormController = require('web.FormController');

FormController.include({
_onButtonClicked: function (event) {
if(event.data.attrs.id === "darkroom-save"){
//your code
}
this._super(event);
},
});
Avatar
Discard
Best Answer

What if i use a developer mode option to extend an existing form?

Where would I add the JS code? is there a global option where all this could be placed? 

If I do not understand incorrectly my button code lives on DB.

This is the form I have added an extra button, and I want either to fire a HTTP call to another server from the on_click of the button.

Here is where I edit the form: web?debug#action=26&model=ir.ui.view&view_type=list&menu_id=4

Thank you very much in advance.

Avatar
Discard