I have a problem with a widget I just created.
I have an oh-button that activates an f7-popover that contains oh-links. Each oh-link assigns a different value to the same variable.
This works when there’s a single widget, but not if there’s more than one.
I know I can get around this by creating as many widgets with different variable names, but if anyone has another solution I’m interested.
This is a funny quirk of how the f7 modals work. Even though you build this popover in three different widgets, because you give it the same class in each three, the f7 library overwrites each popover with the next one. This means that really each of your widgets is opening the popover for the third widget because that was the last popover created (which explains why it is only the value in the third widget that is changing no matter which widget opens the popover).
There are two essential solutions to this. One is easy but winds up with multiple (possibly resource intensive) popovers, the other is a little more involved, and utilizes the single popover but makes it dynamic enough to link to the widget that opened it.
First solution: Just give each of your widget popovers a different class. Add a property to your base widget that is a string which allows you to set an extra identifier for your popover (or just use the mode_chauffage property that is already unique to each widget). Then on the popover class itself, the links that open the popover, and the links that close the popover use: detailList + identifier instead of just detailList. For example, if you define a new popoverId property:
Then each time you add the widget to a page and configure the widget make sure to add a unique ID in that property.
Second solution: if you use a variable instead of a property, that variable can be shared between the widgets on a page (and the modal elements they open). So, the button that opens the popover would use the variable action (popoverOpen is an f7 property and is independent of OH so you don’t need to set the button’s action to popover, it can be something else, which is useful here), and set that variable to the value of the item name that widget controls:
The you would change the popover links to use that variable instead of the property. Lastly you would want to add the variable to the page definition as well to make sure that the variables scope is the whole page which means that each widget is sharing the same variable.
I’ve tried to apply your instructions for the 2nd solution and I think I’m making beginner’s mistakes.
I’m not sure about the oh-link modification: (actionItem: =vars.popoverItem)
By doing this, only the last widget added works. If this last widget is manipulated, then the first two widgets “work” but modify only the last widget.
also, I haven’t yet declared the variable in the page containing the 3 widgets, would this do?
What you’ve posted should work depending on the value of vars.popoverItem. Without seeing the whole code as it stands at the moment I can’t say exactly what’s wrong, but it sounds like popoverItem is not being properly set in the other widgets.
No, to define variables for a page, you have to add the defineVars parameter to the config of the page itself.
I stand corrected. You properly modified your configuration, but the popovers are not updating the way they should in response to variable changes. Even attempting to force an update doesn’t seem to be working. I wonder if this is another side-effect of the new caching that hasn’t been reported yet?
I’m going to have to dig into this a little more deeply to see where the error is.
In the meantime, I am 100% confident that the first method I mentioned (unique IDs for the popover classes) will work.