Is there a way to extract the interfaces out of the list returned when we do an a!applyComponents?

Is there a way to extract the interfaces out of the list returned when we do an a!applyComponents?

For example, I'm using the choose() function with an a!applyComponents like this:

choose(
local!currentStep,

rule!interface1(),

a!applyComponents(
function: rule!interfaceLoop(index: _, array: ri!array),
index: _,
arrayVariable: local!itemsToken),

rule!interface6()
)

But when using the applyComponents here it's evaluated as:

choose(
local!currentStep,
rule!interface1(),
{
interfaceLoop(index: 1, array: ri!array),
interfaceLoop(index: 2, array: ri!array),
interfaceLoop(index: 3, array: ri!array),
interfaceLoop(index: 4, array: ri!array)
},
rule!interface6()
)

Is there a way to extract the interfaces returned by the a!applyComponents so if local!currentStep=3, it would return the interfaceLoop(index:2, array:ri!array) instead of rule!interface6() ?

OriginalPostID-221284

OriginalPostID-221284

  Discussion posts and replies are publicly visible

  • typo above: the index: _ on the first choose() block above should be enumerate(count(ri!array)) assuming ri!array is not empty
  • @nickh Hi, the requirement can be accomplished provided if the array of arrays built by fn!choose() is flattened and below is an example of how you can flatten.


    a!formLayout(
    firstColumnContents: {
    fn!index(
    {
    rule!interface1(),
    \ta!applyComponents(
    \ tfunction: rule!interfaceLoop(index: _, array: ri!array),
    \ tindex: _,
    \ tarrayVariable: local!itemsToken
    \t),
    \trule!interface6()
    },
    local!currentStep,
    null
    )
    }
    )
  • This almost works, but what if we have a situation where rule!interface1() contains an array of components we want to display together, or we want to display different interfaces grouped together?

    For example:

    fn!index(
    {

    {
    a!sectionLayout(title: "display section title for interface 1"),
    rule!interface1()
    },
    a!applyComponents(
    function: rule!interfaceLoop(index: _, array: ri!array),
    index: _,
    arrayVariable: local!itemsToken
    ),
    rule!interface6()
    },
    local!currentStep,
    null
    )
    }
    )

    When we go through this interface it would show:
    local!currentStep=1: a!sectionLayout(title: "display section title for interface 1"),
    local!currentStep=2: rule!interface1(),
    local!currentStep=3: rule!interfaceLoop(1, ri!array)



  • @nickh Yep, it works. If you would like the element (chosen based on the selected index) to show more than one component, opt for a Section Component which can wrap one or more than one component inside it. This way we can also stay away from the fear of flattening. For instance, if you are expecting the rule!interface1() to display more than one component, make sure that all the components are wrapped in the Section Component.

    If the rule!interface1() contains an array definition of two Section Components or an two Text Field Components, they will be flattened.

    Finally I would like to say that whatever you have specified under 'When we go through this interface it would show' is how the interface is going to be executed as per my knowledge. Simply speaking, the array of array flattens and now each element is able to render ONE component(be it a Section or Text Field or Dropdown Field and so on) at a time.
  • Our interfaces do have multiple sections that need to be displayed on one page, so using the index that flattens those interfaces doesn't work for our purposes.


  • @nickh Then in that case, you may need to go ahead with fn!choose() which deals with an array of arrays but you may need to plan for a workaround again. There isn't any alternative I could think of at the moment..
  • @nickh647 were you able to find a work around?
  • Yeah, we kind of had to rethink how we structured the interfaces. Basically if the current step is on the 'array' interface (interfaceN), we step through the indexes of that array until we reach the end of the array, and then we would increment the currentStep to get to the next interface (interface3). Kind of like this:

    choose(
    local!currentStep,
    rule!interface1(),
    rule!interfaceN(
    index: local!index,
    array: local!array
    ),
    rule!interface3()
    ),

    a!buttonWidget(
    label: "Next",
    value: local!currentStep+1,
    saveInto: {
    if(and(local!currentStep=2, local!index<count(local!array)),
    a!save(local!index, local!index+1),
    a!save(local!currentStep, save!value)
    )
    }