Help

1

Avoid calling write function on button click

Avatar
laribi

Hello,

Can i please avoid calling the write method of the model when i click on a button ?

Thanks,

2 注释
头像
丢弃
Avatar
Gopakumar N G
-

On which method you want to do this, can you explain your requirement?

Avatar
laribi
-

Hello, When i click on any button in Openerp , it call before the write method of the model to save the record. I want only call the button function.

1 答案
0
Best Answer

This is an old question, and the exact context is not given, still here's how I managed to achieve that in 12.0:

First, the button should look like a button but not be an actual button tag so Odoo won't attach a click listener to it:

<a class="btn btn-primary myapp-dothis" tabindex="0" role="button">Do this!</a>

tabindex is necessary for Bootstrap CSS to correctly apply, and role is to avoid XML validation warnings.

Then use your favorite way of attaching your event to the button. Could be an onclick attribute, or if your button is in a view used in a JS widget, use the events property:

const MyEditor = dialogs.FormViewDialog.extend({
    events: {
        'click .myapp-dothis': 'onDoItClick'
    },
    onDoItClick(ev) {
        ...
    },
头像
丢弃