Search code examples
odoo-14

custom layout in form views in Odoo 14


I need a form view and I need its layout to be customized, using directly the Bootstrap 4 styles

How exactly can I do that ?

Also

I need some fields/tabs to appear conditionally (if some values is true) and such conditionally appearing fields need to be in my custom layout

Is this possible ?

How ?

First of all, I could use an example of a custom layout

And then I could use some enlightenment on how the conditional appearing of fields is done, behind the scenes

Thanks in advance


Solution

  • You can create a form view using any html you like. You can also use xpath to load custom css and javascript, such as bootstrap. You should load the xpath straight after your opening form tag.

    <xpath expr="." position="inside">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    </xpath>
    

    There a couple of ways to show things conditionally. I find the following example easiest when using the form views:

    <div id="my-div" attrs="{'invisible': [('field','==',True)]}">Do not show this text if the field is true</div>