How to add validation to an inline grid addRowLink?

I have an Inline Grid created, which has addRowLink, used to create a new row each time it is clicked but the scenario is that the user should not be able to click that link more than 5 times, i.e. after creating a 5th row, the link should be disabled and a validation error should be thrown. Any suggestions appreciated?

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    The simplest way to do this is just remove the Add Row Link when you have reached the maximum number of grid elements.  The Add Row Link itself doesn't have a validation configuration.  You could add validation on the Grid itself, but assuming you set up the Add Row link properly, there should be no way by which the validation condition could ever become true.

    Quick example:

    a!localVariables(
      
      local!gridContents: {
        {
          id: 1,
          name: "asdf"
        }
      },
      
      a!sectionLayout(
        label: "Test Grid",
        contents: {
          a!gridLayout(
            headerCells: {
              a!gridLayoutHeaderCell(label: "Id"),
              a!gridLayoutHeaderCell(label: "Name")
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "NARROW")
            },
            rows: a!forEach(
              local!gridContents,
              a!gridRowLayout(
                contents: {
                  a!textField(
                    value: fv!item.id,
                    readOnly: true()
                  ),
                  a!textField(
                    value: fv!item.name,
                    saveInto: fv!item.name
                  )
                }
              )
            ),
            addRowLink: a!dynamicLink(
              label: "Add Row",
              /* in older versions of Appian, using a showWhen here would result in an error condition, 
                so it was necessary to wrap the whole dynamicLink in an if() statement.  This seems to 
                now be fixed (as of Appian 19.4) */
              showWhen: length(local!gridContents) < 6,
              saveInto: {
                a!save(
                  local!gridContents,
                  append(local!gridContents, {id: null(), name: null()})
                )
              }
            )
          )
        }
      )
    )

  • lol. Even I came up with the same solution. Thanks for confirming...