Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
11950 มุมมอง

Hello everyone,I hope all of you are fine.I have  one question,the question is that suppose I have a field of type selection in my class model.Suppose following is the field :


q_test = fields.Selection ( selection = [( 'n' , 'Normal' ), ( 'abn' , 'Abnormal' )], string = 'my field' )

Now suppose I want that when the user selects Abnormal option from the selection field,the text displayed to the user on frontend should be red,and if the user selects the option Normal,then it should be displayed as normal (i.e Black color font).

How can I achieve this,should I use some widget for it or is their any builtin option available in Odoo that can help me perform this task.

Thank you in advance.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Omar
You can apply one trick to show different color for selection field.

<field name="gender" string="Gender" style="color: red;" attrs="{'invisible': ['|',('gender','=','female'),('gender', '=', False)]}"/>
<field name="gender" string="Gender" style="color: green;" attrs="{'invisible': ['|',('gender','=','male'),('gender', '=', False)]}"/>
<field name="gender" string="Gender"  attrs="{'invisible': ['|',('gender','=','male'),('gender','=','female')]}"/>

Thanks.
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Omar,

Might this work for you

Add decoration in view

อวตาร
ละทิ้ง

<field name="q_test" decoration-danger="q_test == 'abn'" />

ผู้เขียน คำตอบที่ดีที่สุด

This is not working in my case,and also even if it works,then dont you think its not that good an approach because its quite static,hard coded,as you can see that in this example we have just 2 values,suppose when we have more than 2 values,like 10,15 values and I want to give different colors to them

For example the field is country=fields.Selection() and in that field we have 30 countries,so I will have to give different color to all the fields by writing <field='country'.....> 30 times.So is their any better and dynamic solution for this kind of problem like using some widgets or javascript code by which we get the value of selection field when user enters the data like ,document.getElementById('xyz').fontcolor='blue' ,something like this?Any such solution?Does that exist?Suggestion on this problem will be highly appreciated.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ธ.ค. 19
4203
2
ต.ค. 24
1210
0
เม.ย. 22
4023
1
พ.ค. 21
3751
Odoo Selection field issue แก้ไขแล้ว
3
มี.ค. 24
6933