Skip to main content
Known Participant
Jun 21, 2023 8:36 AM UTC
Question

Duplicating Section layout on button click

Hi, I have a requirement where I need to duplicate a particular section on clicking add button. In the section I have some text fields and clicking on the "Add" button the text fields should get duplicated where I have to enter new values in the field. Is it achievable? or is there any other method where I can duplicate the fields on clicking the button ?Please let me know

Thanks

    9 replies

    sanchitg0002
    Inspiring
    Jun 21, 2023 8:41 AM UTC

    You can achieve this with the help of a!forEach() 

    Example: 

    a!localVariables(
      local!count: 1,
      {
        a!forEach(
          enumerate(local!count),
          a!sectionLayout(
            label: "Section",
            contents: {
              a!textField(
                label: "Text",
                labelPosition: "ABOVE",
                saveInto: {},
                refreshAfter: "UNFOCUS",
                validations: {}
              )
            }
          )
        ),
        a!buttonArrayLayout(
          buttons: {
            a!buttonWidget(
              label: "Add Section",
              style: "NORMAL",
              saveInto: a!save(local!count, local!count + 1)
            )
          },
          align: "START"
        )
      }
    )

    Known Participant
    Jun 21, 2023 9:39 AM UTC

    Thank you Very much

    harshitb6843
    Brainy
    Jun 21, 2023 9:43 AM UTC

    Please consider accepting the answer so if any one else is facing the same issue, they can look at the solution that was working.