Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
4988 Zobrazení

Hello,

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

Thanks,

Avatar
Zrušit

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

Autor

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.

Nejlepší odpověď

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
Zrušit