콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
20273 화면

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.

아바타
취소
베스트 답변

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;"/>

아바타
취소
작성자 베스트 답변

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.

아바타
취소

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.

작성자

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.

관련 게시물 답글 화면 활동
2
6월 17
6328
1
2월 25
975
1
3월 23
4568
1
3월 25
2610
Editing Fields 해결 완료
2
11월 20
3288