Skip to Content
Menu
This question has been flagged
2 Replies
3237 Views

HI all,




I struggled a bit with the situation, trying to add css class to a field.


This was my first attempt, which didn´t really work correct in the process, even if the classes were added correctly on the field:


- If test_field == True add class for decoration-danger


- and always add test_class


Classes were set correct on the field, but it didn´t change if test_field was != True



xpath expr="//field[@name='user_id']" position="attributes"               		​​attribute name="decoration-danger" "user_id_timeoff==True" attribute     	​attribute name="class" time_off_warning attribute
xpath





Then after a lot of wondering and some info on google, I tried this, and it worked just fine even if I wanted to avoid replacing the user_id field:


xpath expr="//field[@name='user_id']" position="replace"               
field name="user_id" class="time_off_warning" decoration-danger="user_id_timeoff==True"   
xpath


             Sorry can´t post it other than that








 





Avatar
Discard
Best Answer

Hey Jörn Göpel,


I hope you are doing well.


1. Position "Attributes":

    - With "attributes," you can tweak various characteristics of XML elements in Odoo views. This includes things like adding CSS classes (for styling), changing widget types (for user interaction), and adjusting other attributes that control how the interface appears and behaves.

    - The specific attributes you can modify will depend on the context and the particular view you're customising. You have the flexibility to fine-tune these details to your liking.


2. Position "Replace":

    - On the other hand, "replace" is used when you want to do more than just tweak attributes. It allows you to go further by modifying or even entirely replacing existing views, fields, or elements in an Odoo module.

    - This means you can completely change how a part of the interface looks or works. It's like taking out an old puzzle piece and putting in a new one that you've designed yourself. This gives you more control and customisation power, particularly when you need to make significant changes to the interface.


I hope this will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com     

Skype: kalpeshmaheshwari

Avatar
Discard
Author Best Answer

Hi Jainesh,

thank you for your answer that clearifies a little bit more of my understanding :)

I was really confident in using position="attributes" with 

/ "user_id_timeoff==True" /

that it will work with the given condition on the field, but odoo seems to not parse this correctly.

So the "replace" of the whole field with the decoration-danger attribute was necessary, which cost me some time to convince myself that I should just go the "replace" way.

But your explanation made it very clear, why the replace makes sense here.


Best Regards



Avatar
Discard