UI 3 Label card: conditional action

In a label card, I’d like to configure a conditional action, i.e., it is only executed when an item has a certain value.

Is that possible?



I used actionGroupPopupItem in a oh-list-item.
This works perfect. However, for some items I don’t want a popup.
In this case the “>” should not be displayed in the widget.
However, as soon as I add “action” in the code, the “>” is visible, doesn’t matter what expression is defined.
How can I make this conditional?


no-chevron: true

to your item. You can also make this an expression instead of just true so that it shows when you want it.

1 Like

Many thanks again - it works :slight_smile:

I’m just wondering I can improve the condition.

I would rather like to make the expression based on the item type, instead of using undefined as the condition.
In case type is ‘Group’, then condition should be false, hence the chevron icon is visible.
In case the selected item is a ‘Switch’, etc., the condition should be true and the icon should be hidden.

 actionGroupPopupItem: =props.itemGroupPopup
 no-chevron: "=(props.itemGroupPopup === undefined ? true : false )"

Unfortunately I didn’t find a way to match with Typeof - maybe it did it wrong.

This is actually a little difficult. There is no direct access to the item type in the widget expressions. The items object does have a type property, but that actually refers to the type of state being reported. So, items.someSwitchItem.type will actually be "OnOff" because that is the state type that a Switch item has. A Group item can have a state if it has been given an aggregation function, but usually it has a state of NULL because groups do not have states by default. So items.someGroupItem.type will actually return UnDef unless that group has an aggregation function.

Unfortunately, any item will a NULL state will return the same UnDef so that is not a 100% reliable way to detect a Group item.

The only way to get the actual group of an item is to have that item returned by a repeater using one of the repeater options that collects a list of items. In that case, the information returned is the entire json description of the item which does include the actual item type.

If you just want to clean up the condition as you have it, then that is reasonably simple. undefined is a falsy value and any defined value is a true value. So you don’t even need the ternary statement. You can just set

no-chevron: =props.itemGroupPopup

If the property is defined in the widget, then the value will be true and the chevron will be suppressed. If the property is not defined in the widget, then the value will be false and the chevron will be drawn.

1 Like

Many thanks for the detailed explanation, it helps a lot - again something new learned today :slight_smile:

I will use the approach you mentioned - it is fine for the widget I use. :+1: