İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
4987 Görünümler

Hello,

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

Thanks,

Avatar
Vazgeç

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

Üretici

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.

En İyi Yanıt

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) {
        ...
    },
Avatar
Vazgeç