Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to set a custom css class on a field in a form view?

By
Pascal Tremblay
on 2/4/16, 10:01 PM 1,436 views

Hello all,

For example, I would want this field has the class="residual" in the final html source code of the form view. So, I could select it with css after.

How to attrib this custom class? 


For example this class "residual" doesn't  appear on the final source code of the page :

<field name="residual" class="residual" groups="account.group_account_user" widget="monetary" options="{'currency_field': 'currency_id'}"/>


Thanks

 

UPDATE #1

I have also tried this one. "residual" class still not appears in the HTML source code.

<field name="residual" cssclass="residual" groups="account.group_account_user" widget="monetary" options="{'currency_field': 'currency_id'}"/>


UPDATE #2

This line doesn't have effect too.

<field name="residual" style="color:red;"  groups="account.group_account_user" widget="monetary" options="{'currency_field': 'currency_id'}"/>




Are you asking how to add new CSS to Odoo then?

Yenthe
on 2/5/16, 3:14 AM

my new styles.css sheet is already loaded in the source html. but I can't find a selector to get this field only! thanks

Pascal Tremblay
on 2/5/16, 7:15 AM
0
William Brugger
On 2/6/16, 11:43 AM

This has worked for me.

Pass your custom class and existing class like this. You can find out what the existing class is by using something like firebug or just "view source".  Just a space, no comma between classes. 

 <field name="residual" position="attributes">
    <attribute name="class">the_existing_class residual</attribute>
</field>

FYI, you can use attribute name="class" add="residual" in V9 only

Jérémy Kersten (jke)
on 2/6/16, 4:59 PM
0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 2/6/16, 3:13 AM

Hello,

If you added new css class to your custom module. You need to link this new .css by using:

<template id="assets_backend" name="module_name assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
                 <link rel="stylesheet" href="/path/to/s/.css"/>
</xpath>
</template>


in your .xml file. 

You can check this question also 

Hope this could help

Thanks for your answer, but it is not what I need. My CSS stylesheet is ALREADY loaded in the source code. I want to know how to attrib the "residual" class to a field.

Pascal Tremblay
on 2/6/16, 9:49 AM
0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 2/6/16, 11:35 AM

Here is our solution. 


In the account.invoice_form view :

<group class="oe_subtotal_footer oe_right  invoice-residual-view">
<field name="residual" groups="account.group_account_user" widget="monetary" options="{'currency_field': 'currency_id'}"/>
</group>



In our custom styles.css :

.invoice-residual-view {
font-size: 24px;
color: #154734; !important;
border: 3px solid #009A44;
font-weight: bold;
}
.openerp .oe_form .oe_subtotal_footer.invoice-residual-view td.oe_form_group_cell {
vertical-align: middle;
padding: 3px 6px 3px 3px !important;
}


And the result :

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/4/16, 10:01 PM
Seen: 1436 times
Last updated: 2/8/16, 8:15 PM