Toggle a class for an alert based on 3 conditions

Hello,
I’ve been searching throughout the forum and documentation, including reports such as this one, and I am not clear if what I want is feasible:
I have an alert, and I want to change its type (danger, warning, success), based on a condition picked up on page loading from an expression. I have tried toggling class and assigning dynamic attributes, but I must be doing something wrong.
Base code is:

<div class="alert alert-danger" role="alert" id="alert_impact"></div>

Hello,
Yes you need to add a dynamic attribute for the class and pick your condition per each of the classes you want to add.

Thanks @Teodor, I understand the concept, but I struggle with the implementation, in the sense that I’m not sure where to start by adding a dynamic attribute in the first place. If I then use the condition to change the class, it doesn’t have an effect:

<div class="alert alert-danger" role="alert" id="alert_impact" dmx-style:alert-warning.important="(serverconnect_current_escalation_qualifiers.data.current_escalation_qualifiers.eq_tier == 2)" dmx-style:alert-warning.important="(serverconnect_current_escalation_qualifiers.data.current_escalation_qualifiers.eq_tier == 2)">

You are using the wrong dymanic attribute. You need to use class toggle not style.

3 Likes

Thanks @brad and @Teodor. It works indeed.
For any further person ever researching this topic, this is the screenshot of the working setup and the resulting code:

<div class="alert alert-danger" role="alert" id="alert_impact" dmx-class:alert-danger="(serverconnect_current_escalation_qualifiers.data.current_escalation_qualifiers.eq_tier == 1)"

dmx-class:alert-warning="(serverconnect_current_escalation_qualifiers.data.current_escalation_qualifiers.eq_tier == 2)"

dmx-class:alert-success="(serverconnect_current_escalation_qualifiers.data.current_escalation_qualifiers.eq_tier == 3)">
2 Likes