Mark_VG
(Mark)
April 23, 2021, 8:37am
1
Hi All
I am setting up a generic widget using props to populate the display.
As a result there may be times when a component refers to a non-existent Item - which I would prefer to hide.
- component: oh-label-item
config:
action: group
actionGroupPopupItem: =(props.partitionPrefix) + '_Doors'
item: =(props.partitionPrefix) + '_Doors'
title: =(props.partitionPrefix) + ' Doors'
icon: oh:motion
iconUseState: true
- component: oh-label-item
The above is an example of a component I am using. I know I can hide the component based on the state of the item, however cannot find out how I can hide the component if the item does not exist?
- component: oh-label-item
config:
visible: '=(items[props.partitionPrefix + "_Doors"].state === "ON")
action: group
actionGroupPopupItem: =(props.partitionPrefix) + '_Doors'
item: =(props.partitionPrefix) + '_Doors'
title: =(props.partitionPrefix) + ' Doors'
icon: oh:motion
iconUseState: true
- component: oh-label-item
Any suggestions or advise would be appreciated.
Thanks as always
Mark
rlkoshak
(Rich Koshak)
April 23, 2021, 4:05pm
2
I don’t know for sure but maybe =items[props.partitionPrefix+"_Doors"] === undefined
might work.
1 Like
Mark_VG
(Mark)
April 23, 2021, 4:49pm
4
Thanks @rlkoshak . Always appreciate your help.
I need to hide to the component if the item does NOT exist. The syntax hides the component, but also a valid component.
Tried =items[props.partitionPrefix+"_Doors"] !== undefined
with no luck.
Querying REST API gives:
{
"error": {
"message": "Item Partition3_Doors does not exist!",
"http-code": 404
}
}
So I don’t think, but not sure that undefined would work.
Mark_VG
(Mark)
April 23, 2021, 6:34pm
5
I made an additional component to display the title of =items[props.partitionPrefix+"_Doors"].state
- component: oh-label-item
config:
action: group
actionGroupPopupItem: =(props.partitionPrefix) + '_Doors'
item: =(props.partitionPrefix) + '_Doors'
title: =items[props.partitionPrefix+"_Doors"].state
icon: oh:motion
iconUseState: true
Which gives:
So I can get INVAILD componets to display using
visible: =items[props.partitionPrefix+"_Doors"].state === "-"
Now just now sure how to invert that so they display if the state is NOT “-”?
Tried !==, != etc. My coding is just not up to this.
EDIT…
Sorted:
visible: =items[props.partitionPrefix+"_Doors"].state != "-"
Redraw issue!
rossko57
(Rossko57)
April 23, 2021, 9:50pm
6
Mark_VG:
.state != “-”
Just a caution that you can get valid Items displaying that state too under various circumstances e.g. NULL because not yet initialized or UNDEF due to equipment failure. You may or may not care.
1 Like
Mark_VG
(Mark)
April 24, 2021, 10:36am
7
Thanks for the “Heads Up”. I had only briefly considered the implications. Though in my case I don’t think it is a critical concern. If the component does not display then there is an issue with the config (or the item doe snot exist because it is not required.
I am sure there are many use cases for a “Not Exist” condition for visibility.
Always interested to hear better /other solutions?
JustinG
(JustinG)
April 24, 2021, 4:47pm
8
I don’t know about UNDEF
, but the items object in widgets does report "Null"
for NULL
states.