Accessing options outside of a nested object

What are you trying to accomplish
I am wanting to have a singular boolean input that alters the showIf of numerous list items.

Desired functionality:

Builder.registerComponent(BuilderComponents.example, {
  name: "example",
  inputs: [
    {
      name: "properties",
      type: "object",
      subFields: [
        {
          name: "accessThis",
          type: "boolean",
          defaultValue: true,
        },
      ],
    },
    {
      name: "sections",
      type: "list",
      subFields: [
        {
          name: "items",
          type: "list",
          subFields: [
            {
              name: "properties",
              type: "object",
              subFields: [
                {
                  name: "FromHere",
                  type: "boolean",
                  showIf: `options.get("accessThis")`
                },
              ],
            },
          ],
        },
      ],
    },
  ],
});

showIf: options.get("accessThis") does not work like this, and options is unable to get “accessThis” from this location of the object.

You cannot use the traditional showIf functionality within nested subFields due to (options, parent, parentElements) => { } being unable to be directly serialized and passed as an argument in a postMessage function call.
This can be normally worked around by utilizing stringified queries like options.get("accessThis")

That however only works within the immediate scope. Is there a different current functionality to allow for accessing “accessThis” from within a nested subfield?

Hello @Sevrene,

Currently, this is not possible. However, it’s great feedback and a feature to have. We would request you kindly submit a feature request at Builder.io Ideas

Thank you!

I know it’s a little too late :wink:
But maybe it will help somebody else:

options is JSON with values set for all your inputs for your component (you can see it with a right click and choosing “JSON view”).

You can do whatever is possible to do with map type of data in JS, so e.g. get and set values.

So in your example, you can try: options.get('properties').get('accessThis') - it should get the current value from nested accessThis field (but will rather not change when you change its value).

1 Like