1
0
-1

Hi,

I have a repeat block that needs a business rule applied.

However, I cannot seem to get the correct behavior; in the block there is a dynamic data button and some data fields. when the button is clicked the data fields are reset to blank, ready to receive the new data result.

But what is happening is when button 1 is clicked all the data fields are reset, based on how many repeats are present. the same occurs when button 2 is clicked - all data fields are reset.

I would like to reset only the associated data fields:

  • button 1 > reset data fields in block 1
  • button 2 > reset data fields in block 2, etc

I understand that I need to capture the repeat index and use that to specify the target.

However, within the repeat block the data fields are not selected as 'array', and outside the repeat block I am having trouble getting the target repeat index (i.e. what is the index of the button that was clicked?)


Would appreciate any guidance.

Thanks


    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Hi Mark

      Assuming your button is inside the repeat then in its click script you can simply point at each of the other fields in the row (one by one), change the type to node (and triggering type to static) and use sfc.setRawValue({node},"") to clear them

      (If you point at a field from within the repeat you will just be given the single field on the same row)

      You also asked how to find the current row index, there are a couple of ways of doing this.

      One is to drop in a 'Repeatable Block Index' widget into the repeat (this is a hidden field whose value will be the index of the row it is in) and simply point at this widget from within a rule on the same row, A second way is to point at the instance manager and ask it what the index of the button is.

      You can get the instance manager by pointing at the repeat itself from the button click script changing the type to IM if necessary) and using the findInstanceIndex method of the instance manager (passing in the button node) to find its index

      https://transact.composer.avoka.com.au/composer/doc/jsdoc/symbols/SfcInstanceManager.html


      1. Mark Murray

        Hi David, Bill,

        thanks for the suggestions, very helpful to get me going in the right direction.

        I managed to get this working; I had to use the sfc method to get the instance manager based on the noderef and then get the IM index, then target the fields for that index.

        It was a little bit of work to get the IM, but once i had that I made quick progress.

        Thanks

        Mark

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

      Hi Mark,

      You might find this short video useful to help understand repeats.  All about repeating data

      As a quick example, I've created a repeating block with a text field and button.  On the button I have a click rule:

          data.$r[data.$i].textField = 'Hi ' + data.$i

      This rule will set the text field in the same repeat instance as the clicked button to 'Hi x' where x is the repeat index.

      So the index of your clicked button is in data.$i, and other fields in the same repeat instance are available at data.$r[data.$i].whateverFieldYouHave


      1. Mark Murray

        Hi Bill,

        thanks for the video link and the code sample above.

        The video is directed at Maestro, and the code above looks like Maestro as well.

        However, I am working with a Composer form; do you have a code sample for Composer to achieve the same thing; capture the repeat index and use it in the business logic?


        Thanks

        Mark

      2. Mark Murray

        Hi Bill,

        I found this article: https://support.avoka.com/kb/display/TKB/Using+JavaScript+to+access+fields+in+repeat

        it gives some basics, but I find I need a bit more detail. Is there an example I could follow, or any other references?

        Thanks

      CommentAdd your comment...