I try to open and close a popover by settings its property opened to true or false depending on an item’s state. The expression is not the problem.
However, it is not possible to set this property to true or false with an expression.
I tried various test expressions like: '=("1" == "1") ? "true" : "false"' '=("1" == "1") ? true : false' '=("1" == "1") ? "1" : "0"' '=("1" == "1") ? 1 : 0'
those are always true and the expression‘s result is also „true“. but the popover does not appear. Probably a type conversion to bool problem?
If you write directly into yaml code opened: true
the popover appears and disappears when changing to opened: false
So the code is doing fine.
first of all, thank you - I’ve learned something that I wasn’t aware of until I read your question.
I thought it won’t be possible currently to open/close popups or popovers depending on item states - now I know, it is.
Sadly the popover seems to have some problems finding the element (which the class is applied to) if the item is triggered via item state - so it will open at the 0,0 location (top left corner) of the screen, if no action was triggered from the action element before.
But popups for example, would work flawlessly here.
Be aware, that the action will only trigger if the item value changes and not if the item gets update to the same value over and over again
He Rainer,
thanks again for your help.
But I am not sure if I understand you.
My problem is not the layout, where the popover appears on the screen.
I simply can’t open and close it automatically.
whene entering opened: true in yaml code it opens and when entering opened: false it closes.
the basics are working fine. I do not even need a button to trigger the popover.
the only thing is, no expression is working which passes true or false to the property. unfortunately your code is also not working…
PS: yes, right. that was exactly the use case behind this post.
Ok, maybe it’s me then, who is not understanding your question correctly
I thought the “1” in your expression…
…was just a placeholder for an item which state should open your popover.
This is where I replaced the (“1” == “1”) (which - should - always be true) with the testItem expression (items.YOURITEM.state === "1")
If you change the state of YOURITEM to 1 now your popover should appear.
To be honest, I don’t really understand why this expression '=("1" == "1") ? true : false', which is correct and should be return true, doesn’t work… But if you use a real item state here, it will… Maybe @ysc have a proper explanation here?!
I see - my fault…
This is just a test expression. It is always true, but the popover never appears.
In this post it is not about to the expression itself. It is about the problem that the expression cannot handover its result (true or false) to the property.
Hi Rainer,
this popover can be launched completely independent from any button click - purley triggered by an item or an event - very powerful!
Copy paste this widget and you will see when typing “false” while the popover is active, the popover closes automatically …
IF it would work with an expression that would be fantastic!
Let’s wait and see if yannick finds some time to answer.
I think theres still a slight missunderstanding here (don’t know anymore on which site tbh )
If you exchange your item-name with YOURITEM and give it the update ‘1’, it’ll work already (with the above mentioned limitations)
ok. getting closer now. basically it is exactly how it should be. however, it is not working on my end.
the testItem you created is of type number, right?
I was using exactly your code. Log file shows change of testItem. But nothing happened.
Yeah, it does… - but didn’t work inside the above widget code. I quickly checked it with the ‘visible’ prop inside a random f7-card - and it works there too. So no general expression problem.
Maybe it does not work in the case of this widget here, because the opened config parameter only reacts on changes and not on frequent, identical, updates. But not that big of a problem, I think…
Hey Rainer,
just wanted to thank you for your support. At least, we got a popover working depending on an item’s state. Currently we seem to need a string item instead of a switch item.
worst case I need to rewrite some rules and change the required items.
@ysc : from my side I do not regard this as an issue, as there is a workaround. so no priority…
ok. here we go: I think there is a bug in f7-popover. opened: '=(items.testItem.state == "ON") ? true : false'
works perfectly in f7-popUP element but not in f7-popOVER