İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
20263 Görünümler

I have a standard form view that includes a computed float field as follows.

<field name="x_margin"/>

I would like to change the color of the field based on it's value.

For example

0 < x_margin < 0.1 == red

0.1 < x_margin < 0.2 == yellow

x_margin > 0.2 == green

I know I can set the color of the field like this

<field name="x_margin" style="color:red"/>

but I can't figure out how to apply conditional formatting to a style.  Everything I've found in searching seems to only apply to the tree view. I would like to apply this to a field in a form view.

Avatar
Vazgeç
En İyi Yanıt

Can you just put a label above/below/near the field?





Don't  follow this snippet exactly - I used the existing MARGIN field which is a flat dollar margin amount - but you should be able to get what you want if you understand what I did here:

<label colspan="2"

            string="YOU ARE FIRED IF YOU SELL AT THESE PRICES"

            attrs="{'invisible': [('margin','&lt;', 45)]}" style="background-color:yellow;"/>

<label colspan="2"

            string="HEALTHY COMMISSION CHECK COMING YOUR WAY!"

            attrs="{'invisible': [('margin','&gt;=', 45)]}" style="background-color:palegreen;"/>

Avatar
Vazgeç
Üretici En İyi Yanıt

Ray Carnes thanks for the help - I used your idea and did this instead.  

<field name="x_elec_lab_mar" attrs="{'invisible':[('x_elec_lab_mar','&lt;',0.3)]}" style="background-color:yellow;" nolabel="1" readonly="1"/>


<field name="x_elec_lab_mar" attrs="{'invisible':[('x_elec_lab_mar','&gt;',0.3)]}" style="background-color:green;" nolabel="1" readonly="1"/>

So basically I'm showing the field twice and just making the other condition invisible so it just shows one at a time.  Not the most elegant solution but it does work.  

I was hoping there was a way to directly inject some conditional statement for the style attribute.

Avatar
Vazgeç

Just check the the field has a value both times - there aren't many cases where you can show a field twice in the same view and have the value work on the second occurance of the field.

Üretici

I actually have it on there 3 times (3 colors) and it seems to work for all cases. I tested it and changing a value changes all 3 instances. Thanks for the warning though. I will keep an eye on it.

İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Haz 17
6319
1
Şub 25
957
1
Mar 23
4544
1
Mar 25
2606
Editing Fields Çözüldü
2
Kas 20
3275