Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
1733 Lượt xem
How could I change the style of a field dynamically based on a condition, specifically I want to change the background color of the name field of a task in the project, set it to the same color as it has in the kanban view


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi, 

Please try to use t-attf tag inside the record


example:

t-attf-style="background:{{condition?red:blue}};"


in this if the condition satisfies it takes red and else it takes blue

Regards

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

A workaround to achieve something like this is to add multiple fields and make them visible for the given condition. So something like this:


<field 

   name="my_field" 

   string="My Field" 

   class="class_green" 

   attrs="{'invisible': [('condition', '!=', 'value')]}" 

/>


<field 

   name="my_field" 

   string="My Field" 

   class="class_red" 

   attrs="{'invisible': [('condition', '!=', 'other_value')]}" 

/>


I hope this helps!

Ảnh đại diện
Huỷ bỏ