Functions in Widget not usable on page

Hi,

I’m working on a widget and code is much smaller when using the oh-context with functions. They work in the separate widget but not when you include the widget on a page in grid layout. Looking at browser console the functions are defined on startup but can’t be found when it’s time to use them. Am I doing something wrong or is this just not possible?

grid layout page

config:
  colNum: 8
  fixedType: grid
  ...
blocks: []
grid:
  - component: oh-grid-item
    config:
    ...
    slots:
      default:
        - component: widget:lineChart
          config:
      
lineChart widget:

...
slots:
  default:
    - component: oh-context
      config:
        constants:
          myUnit: "=(props.unit) ? props.unit : (props.average) ?
            items[props.average].unit : (props.current) ?
            items[props.current].unit : '' "
        functions:
          axisLow: "=(x) => (x=='W' ? -4000 : x=='°C' ? -100 : x=='%' ? 0 : -10000)"
          axisMediumLow: "=(x) => (x=='W' ? 0 : x=='°C' ? 15 : x=='%' ? 20 : 0)"
          axisMediumHigh: "=(x) => (x=='W' ? 1000 : x=='°C' ? 25 : x=='%' ? 80 : 1000)"
          axisHigh: "=(x) => (x=='W' ? 4000 : x=='°C' ? 100 : x=='%' ? 100 : 10000)"
      slots:
        default:
          - component: oh-chart
         ...
              visualMap:
                - component: oh-chart-visualmap
                  config:
                    pieces:
                      - color: rgba(80, 200, 90,0.6)
                        max: = fn.axisMediumLow(const.myUnit)
                        min: = fn.axisLow(const.myUnit)
                      - color: rgba(80,90,200,0.6)
                        max: = fn.axisMediumHigh(const.myUnit)
                        min: = fn.axisMediumLow(const.myUnit)
                      - color: rgba(200, 80, 90,0.6)
                        max: = fn.axisHigh(const.myUnit)
                        min: = fn.axisMediumHigh(const.myUnit)
                     ...


What version of OH are you using? There is a known bug with the context on pages in 4.2 and this may be related. If you’ve updated to 4.2.1 or one of the snapshots, then this might be some new issue.

1 Like

That’s probably it. I’m on the release version, in the about menu it says: 4.2.0. I did a forum search but didn’t find that. Is the somewhere a page with known bugs?

edit: But you mentioned 4.2.1 :innocent:. So I performed an update and this version solves the issue!!

edit 2: Did change constants to variables. Somehow the constant caused a delay in loading the widget.

(in the meantime created a minimal setup to reproduce the error, doesn’t matter if you use constants, vars of functions. They all fail.

uid: context_test
tags: []
props: {}
timestamp: Sep 1, 2024, 8:52:00 AM
component: f7-card
config: 
  title: test
slots:
  default:
    - component: oh-context
      config:
        variables:
          myVar: 2
      slots:
        default:
        - component: Label
          config:
            text: = vars.myVar

Not usually, no. There have been few posts about it in the 4.2 release thread and a few other oh-context specific threads, but not too many. It was identified and corrected pretty quickly. Your best chance to see such things is in the github release notes for each version where bug fixes, at least are all listed.