Using Dynamic Links in forEach Function

Certified Associate Developer

I have a dropdown selection within a ForEach loop with two dynamic links: "Add Location" and "Remove Location" that adds or removes a value from the array used to determine the number of iterations. So when you click "Add Location" another dropdown selection appears and when you click "Remove Location" a dropdown selection disappears. The "Add Location" link works perfectly but the "Remove Location" link always removes the last entry in the array because I'm indexing by the fv!item function.

I'd like to get the remove link to remove the same dropdown selection that it is located under. Does anyone have an idea of how to do this?

Thanks.

a!forEach(
              ri!IBRotFaceSym,
              a!localVariables(
                local!numarray: { 1 },
                local!Label: fv!item,
                a!forEach(
                  local!numarray,
                  a!localVariables(
                    local!Sev,
                    local!Loc,
                    local!Pic,
                    local!num: index(local!numarray, length(local!numarray)),
                    a!columnsLayout(
                      columns: {
                        a!columnLayout(
                          contents: {
                            a!sideBySideLayout(
                              items: {
                                a!sideBySideItem(
                                  item: a!dropdownField(
                                    label: local!Label & " Severity",
                                    labelPosition: "ADJACENT",
                                    placeholder: "--- Select a Value ---",
                                    choiceLabels: {
                                      "N/A",
                                      "Light",
                                      "Moderate",
                                      "Heavy",
                                      "Extreme"
                                    },
                                    choiceValues: {
                                      "N/A",
                                      "Light",
                                      "Moderate",
                                      "Heavy",
                                      "Extreme"
                                    },
                                    value: local!Sev,
                                    saveInto: { local!Sev },
                                    validations: {}
                                  )
                                ),
                                a!sideBySideItem(
                                  item: a!dropdownField(
                                    label: local!Label & " Location",
                                    labelPosition: "ADJACENT",
                                    placeholder: "--- Select a Value ---",
                                    choiceLabels: {
                                      "N/A",
                                      "ID",
                                      "OD",
                                      "Face",
                                      "Face ID",
                                      "Face OD",
                                      "Pin Slot",
                                      "Multiple Locations"
                                    },
                                    choiceValues: {
                                      "N/A",
                                      "ID",
                                      "OD",
                                      "Face",
                                      "Face ID",
                                      "Face OD",
                                      "Pin Slot",
                                      "Multiple Locations"
                                    },
                                    value: local!Loc,
                                    saveInto: { local!Loc },
                                    searchDisplay: "AUTO",
                                    validations: {}
                                  )
                                ),
                                a!sideBySideItem(
                                  item: a!fileUploadField(
                                    label: "Upload Photos",
                                    labelPosition: "ABOVE",
                                    target: cons!IBRotFacePics,
                                    fileNames: ri!ControlNumber & " IB Rotary Face " & fv!item,
                                    value: local!Pic,
                                    saveInto: local!Pic,
                                    validations: {},
                                    buttonStyle: "SECONDARY"
                                  ),
                                  width: "MINIMIZE"
                                )
                              }
                            ),
                            a!sideBySideLayout(
                              items: {
                                a!sideBySideItem(
                                  item: a!linkField(
                                    links: {
                                      a!dynamicLink(
                                        label: "Add Location",
                                        value: append(local!numarray, local!num + 1),
                                        saveInto: local!numarray,
                                        showWhen: if(
                                          length(local!numarray) =< fv!item,
                                          true(),
                                          false()
                                        )
                                      )
                                    }
                                  ),
                                  width: "MINIMIZE"
                                ),
                                a!sideBySideItem(
                                  item: a!linkField(
                                    links: {
                                      a!dynamicLink(
                                        label: "Remove Location",
                                        value: remove(local!numarray, fv!item),
                                        saveInto: local!numarray
                                      )
                                    }
                                  ),
                                  width: "MINIMIZE"
                                ),
                                a!sideBySideItem(
                                  item: a!textField(value: fv!item, readOnly: true())
                                )

note: the first forEach statement takes the entries from a multipleDropdownField and creates "locations" based on the choices. The second forEach function is what I am referring to above.

  Discussion posts and replies are publicly visible

Parents
  • Hi jack,

    I took your code for a test. The simple fix is to use fv!index in the remove function. The remove function requires array, index. When you use the fv!item, you are using the value of the item in the array, rather than it's position.

    a!forEach(
      ri!IBRotFaceSym,
      a!localVariables(
        local!numarray: { 1 },
        local!Label: fv!item,
        a!forEach(
          local!numarray,
          a!localVariables(
            local!Sev,
            local!Loc,
            local!Pic,
            local!num: index(local!numarray, length(local!numarray)),
            a!columnsLayout(
              columns: {
                a!columnLayout(
                  contents: {
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!dropdownField(
                            label: local!Label & " Severity",
                            labelPosition: "ADJACENT",
                            placeholder: "--- Select a Value ---",
                            choiceLabels: {
                              "N/A",
                              "Light",
                              "Moderate",
                              "Heavy",
                              "Extreme"
                            },
                            choiceValues: {
                              "N/A",
                              "Light",
                              "Moderate",
                              "Heavy",
                              "Extreme"
                            },
                            value: local!Sev,
                            saveInto: { local!Sev },
                            validations: {}
                          )
                        ),
                        a!sideBySideItem(
                          item: a!dropdownField(
                            label: local!Label & " Location",
                            labelPosition: "ADJACENT",
                            placeholder: "--- Select a Value ---",
                            choiceLabels: {
                              "N/A",
                              "ID",
                              "OD",
                              "Face",
                              "Face ID",
                              "Face OD",
                              "Pin Slot",
                              "Multiple Locations"
                            },
                            choiceValues: {
                              "N/A",
                              "ID",
                              "OD",
                              "Face",
                              "Face ID",
                              "Face OD",
                              "Pin Slot",
                              "Multiple Locations"
                            },
                            value: local!Loc,
                            saveInto: { local!Loc },
                            searchDisplay: "AUTO",
                            validations: {}
                          )
                        ),
                        /*a!sideBySideItem(*/
                          /*item: a!fileUploadField(*/
                            /*label: "Upload Photos",*/
                            /*labelPosition: "ABOVE",*/
                            /*target: cons!IBRotFacePics,*/
                            /*fileNames: ri!ControlNumber & " IB Rotary Face " & fv!item,*/
                            /*value: local!Pic,*/
                            /*saveInto: local!Pic,*/
                            /*validations: {},*/
                            /*buttonStyle: "SECONDARY"*/
                          /*),*/
                          /*width: "MINIMIZE"*/
                        /*)*/
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!linkField(
                            links: {
                              a!dynamicLink(
                                label: "Add Location",
                                value: append(local!numarray, local!num + 1),
                                saveInto: local!numarray,
                                showWhen: if(
                                  length(local!numarray) =< fv!item,
                                  true(),
                                  false()
                                )
                              )
                            }
                          ),
                          width: "MINIMIZE"
                        ),
                        a!sideBySideItem(
                          item: a!linkField(
                            links: {
                              a!dynamicLink(
                                label: "Remove Location "& fv!index,
                                value: remove(local!numarray, fv!index),
                                saveInto: local!numarray
                              )
                            }
                          ),
                          width: "MINIMIZE"
                        ),
                        a!sideBySideItem(
                          item: a!textField(value: local!numarray, readOnly: true())
                        )
                      }
                    )
                  }
                )
              }
            )
          )
        )
      )
    )

  • 0
    Certified Associate Developer
    in reply to jeromew

    Thank you! This worked perfectly!

Reply Children
No Data