0
votes

I've been trying to use t-attf-class in order to disable a button in the header section of Odoo (v11). I've created a button in the header in the view xml file and link it with an action in the model, the action works fine. I'm try to disable the button based on the state condition of the object, I found in the source of Odoo the following template:

<t t-name="FieldStatus.content.button">
    <t t-set="disabled" t-value="!clickable || i.selected"/>
    <button type="button" t-att-data-value="i.id" t-att-disabled="disabled ? 'disabled' : undefined"
        t-attf-class="btn btn-sm o_arrow_button btn-#{i.selected ? 'primary' : 'default'}#{disabled ? ' disabled' : ''}">
        <t t-esc="i.display_name"/>
    </button>
</t>

So I'm trying to do the same for this button:

<form string="Form Name">
<header>
...
<button name="action_delete" string="Delete" type="object" t-attf-class="btn-danger #{state == 'done'?' disabled': ''}" t-att-disabled="state == 'done' ? 'disabled': undefined"/>
...
</header>

the model contains a field state which takes one of the values: ['draft', 'pending', 'done'] This action action_delete is defined in the model and it works fine. I've tried to use the <attribute>inside the button, and the t-if attribute inside and outside of the button with no luck.

P.S. This question is different and the answer doesn't work for this case, also this can be achieved using the invisible attribute which is much easier but we do not want to do this.

1

1 Answers

0
votes

Why not just using the default Odoo way, by making it invisible on some states?

<button name="action_delete" string="Delete" type="object"
    attrs="{'invisible': [('state', 'in', ['state1', 'state2'])]}" />