Change label Bootstrap color

1

How do I change the label color of my button depending on the value it has?

In my form, in the field status , I need the value to be "open", green, "completed" in blue, and "canceled" in red.

I did a function using Thymeleaf but it still is not correct.

Igottheresultdoingso:

<spanclass="badge badge-success"
      th:text="${f.status.descricao}"
      th:classappend="${#strings.toString(f.status) == 'ABERTO' ? 'label-success' : 'badge-danger'}">
</span>

This way it is green when it is in open status, but the other values (canceled, completed) are applied by red color, referring to class badge-danger , this because I do not know how to evaluate the other two options within the function.

    
asked by anonymous 08.12.2018 / 17:20

1 answer

0

You can include another ternary in parentheses after the : of the current ternary.

Instead of:

th:classappend="${#strings.toString(f.status) == 'ABERTO' ? 'label-success' : 'badge-danger'}"

It will be:

th:classappend="${#strings.toString(f.status) == 'ABERTO' ?
'label-success' :
(#strings.toString(f.status) == 'CONCLUIDO' ? 'label-concluido' : 'badge-danger')}"
  

The label-concluido class is just an example. Put the class you want   refers to the "CONCLUDED" status.

    
10.12.2018 / 01:54