bitfocus / companion

Bitfocus Companion enables the reasonably priced Elgato Stream Deck and other controllers to be a professional shotbox surface for an increasing amount of different presentation switchers, video playback software and broadcast equipment.
http://bitfocus.io/companion
Other
1.57k stars 499 forks source link

dynamically generated actions break "isVisible" field #2845

Closed dewiweb closed 5 months ago

dewiweb commented 5 months ago

Is this a bug in companion itself or a module?

Is there an existing issue for this?

Describe the bug

My module (not yet published as a bitfocus repo) https://github.com/dewiweb/companion-module-digitalprojection-mls generate dynamically actions based on constants.js file declaration.

 if (self.REQUESTS[i].type === "range") {
        let basename = self.REQUESTS[i].id.replace(/\./g, " ");
        self.log("debug", "request as range exists : " + basename);
        actions[basename] = {
          name: basename,
          options: [
            {
              type: "checkbox",
              id: basename,
              label: "checked = send command / unchecked = send value",
              useVariables: true,
            },

            {
              type: "dropdown",
              id: basename + " command ",
              label: basename + " command ",
              choices: [
                { id: 0, label: "-- Select Command --" },
                { id: "+", label: "increment" },
                { id: "-", label: "decrement" },
                { id: "#", label: "reset to default" },
              ],
              default: 0,
              useVariables: true,
              isVisible: (options) => {
                options.basename === "true";
              },
            },
            {
              type: "number",
              id: basename + " value",
              label: basename + " value",
              min: self.REQUESTS[i].range[0],
              max: self.REQUESTS[i].range[1],
              step: 1,
              range: true,
              //step: self.REQUESTS[i].step,
              default: 0,
              useVariables: true,
              isVisible: (options) => {
                options.basename === "true";
              },
            },
          ],

All works fine but "isVisible" . Works on static defined action but not in dynamically genarated...

dnmeid commented 5 months ago

for functionality like this you have to use the second parameter of the isVisible function. https://bitfocus.github.io/companion-module-base/interfaces/CompanionConfigField.html#isVisible

Julusian commented 5 months ago

It took me a while to realise why this wasnt working, as that function lookes valid, but there are a couple of mistakes on your side.

1) you aren't returning a value, so the output of your function is always 'undefined'

2) the check options.basename === "true" is checking the value of a property called basename, not using a variable called basename.

So if you pass basename in through the data property, and change that to be (options, data) => options[data.basename] == "true" then you should have more luck