Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
11489 Tampilan

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.

Avatar
Buang
Jawaban Terbai

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.
Avatar
Buang
Jawaban Terbai

Hello Omar,

Might this work for you

Add decoration in view

Avatar
Buang

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

Penulis Jawaban Terbai

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.

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
3
Des 19
3863
2
Okt 24
904
0
Apr 22
3593
1
Mei 21
3476
3
Mar 24
6429