odooqwebodoo-16

How to show data conditionally to record values in form view odoo 16.0


I am trying to show info that depends of the model values in form view

<t t-if="record.id"> ...
<t t-if="record.name == 'Anon'"> ...
<t t-if="name == 'Anon'"> ...

Record and name are undefined

<record id="custom.model_view_form" model="ir.ui.view">
    <field name="name">custom.model.view.form</field>
    <field name="model">custom.model</field>
    <field name="arch" type="xml">
        <form string="Model">
            <sheet>
                <field name="name" />

                <t t-if="record.id">
                    <h1>Hello world!</h1>
                    <button string="Test Button" name="action_test" type="object" class="oe_highlight"/>
                </t>
            </sheet>
        </form>
    </field>
</record>

Solution

  • Use attrs to set invisible attribute based on condition. You can find an example in stock module where a button is hidden when the id field is not set:

    attrs="{'invisible': [('id', '=', False)]}"