1
0
-1

I have a repeating block that I need to pre set the number of repeats based on a dropdown field selection, my attempt to place the following code replicated from one of my composer forms doesn't work. Is there a way to do this is maestro?

 

var num = (data.howManyAdditionalProperties == "3 or more" ? 3 : Number(data.howManyAdditionalProperties ));

data.rptproperty.setInstanceCount(num);                                      

 

var repeat = Form.getItemFromPath(Form.getItemProperty("data.addFormgetitempropertydatacontentitemlabel3","repeatLink"));

repeat.$addItem(repeat.properties.transferFocus);

    CommentAdd your comment...

    4 answers

    1.  
      1
      0
      -1

      Ryan Mazi ThomasYou won't necessarily need the form.setInstanceCount call

      However, to ensure that the object is available, we use a calculate rule after the repeat object in the hierarchy that just does this using a node array:


      No need to use setinstancecount

       

        CommentAdd your comment...
      1.  
        1
        0
        -1

        As of Maestro 5.0.18, you can set the instance count of a repeat with the following method.

        The first parameter can be the item or the "data path string" of the item. The second is the data path of the repeat (which will be an array) and the last is the desired count you want the repeat to be modified to. 

        See example:

         

        Additionally if you want to populate this repeat with some data you can do it with the Util.addRepeatContent method (This has been tested on a page load rule):

        Result:

         

         

        1. Blake Hunter

          Hi David,

          I tried the approach above but whenever I click the "Util.addRepeatContent" button I get the following error: 

          I double checked and my "Form.items.davidRepeat" is of type "repeat". I noticed that the "Form.items.davidRepeat" has a property "repeatingData: true". It seems that the function "addRepeatContent()" has the following line causing the error: 

          I'm not sure why this is the case however. Is there something I am doing wrong or should be doing differently?

          Thanks,

          Blake

        CommentAdd your comment...
      2.  
        1
        0
        -1

        Hi Ben, 

        I am doing something similar and have this working. Here is my code:

        This works fine when the code is triggered via a button click rule, however I need this to be triggered on page load instead. When I try this I get the following error in the console:

        Please can you advise?

        Cheers,
        Ryan

          CommentAdd your comment...
        1.  
          1
          0
          -1

          Hey Jordan, you kind of had the right functions but you are using them in the wrong way.

          Form.getItemFromPath expects a data path as a string (i.e. what you get when you double click a component to add its data path to the script). You will need to call the setInstanceCount function on the result of that call.

          Assuming the field Id of your repeat component was 'content2' and the number of repeats you want to set is contained in a field called repeatCount, your script should be as follows:

          I also would recommend you take a look at this article:

          1. Ben Warner

            Did you get this working Jordan?

          CommentAdd your comment...