Skip to main content
February 8, 2025
Solved

Validations button specific

  • February 8, 2025
  • 5 replies
  • 0 views

I have a scenario where, if I click the "Reject" button, the comments field should be required and cannot be empty. If the "Approve" button is clicked, the comments field should be optional and be submitted. I have a ri!cancel input that changes to true when "Reject" is clicked and false when "Approve" is clicked. However, the validation isn't working as expected. I tried setting the "required" parameter to ri!cancel, but after clicking "Reject" and then "Approve," ri!cancel doesn't seem to change back to false, and still throws validation for approve button if comments is empty

Code for the interface comment field and buttons: 

a!textField(
      label: "Comments",
      labelPosition: if(ri!readOnly, "ADJACENT", "ABOVE"),
      value: ri!TR_Expense_Details.comments,
      saveInto: ri!TR_Expense_Details.comments,
      characterLimit: 250,
      showWhen: ri!TR_Expense_Details.hrApproval = true(),
      required: ri!cancel,
      readOnly: not(a!defaultValue(ri!readOnly, true())),
      validations: if(
        and(
          isnull(ri!TR_Expense_Details.comments),
          ri!cancel
        ),
        "Comment is mandatory when rejecting",
        {}
      )
    )



buttons: a!buttonLayout(
    primaryButtons: {
      a!buttonWidget(
        label: if(
          ri!TR_Expense_Details.hrApproval,
          "Approve",
          "Submit"
        ),
        /*value: false(),*/
        saveInto: {
          a!save(ri!cancel,false()),
          a!save(ri!TR_Expense_Details.dateLogged, now()),
          a!save(
            ri!TR_Expense_Details.hrApproval,
            true()
          )
        },
        submit: true,
        style: "SOLID"
      )
    },
    secondaryButtons: {
      a!buttonWidget(
        label: if(
          ri!TR_Expense_Details.hrApproval,
          "Reject",
          "Cancel"
        ),
        value: true,
        saveInto: {
          ri!cancel,
          a!save(ri!TR_Expense_Details.dateLogged, now())
        },
        submit: true,
        style: if(
          ri!TR_Expense_Details.hrApproval,
          "GHOST",
          "OUTLINE"
        ),
        color: if(
          ri!TR_Expense_Details.hrApproval,
          "NEGATIVE",
          null()
        ),
        validate: false
      )
    }
  )

Best answer by stefanhelzle0001

Did you had a look at validation groups?

5 replies

stefanhelzle0001
February 8, 2025

Did you had a look at validation groups?

sarathkumr268295
February 8, 2025

As suggested by [mention:a11f77a729fb4db2af76b09948583328:e9ed411860ed4f2ba0265705b8793d05] , take a look at the validation group parameter. Also, I am seeing that you are using ri!cancel for required parameter of comments field. Are you initializing the rule input cancel to be true anywhere? Otherwise it wont work, because the moment you click on cancel button, the form will complete and you wont be able to see the validation. You have to set validate parameter to true if you want validations to be shown

mathieud0001
February 8, 2025

If you only have 1 required field, you could simply set validate to false on the approve button. Otherwise, if you have other required fields on your interface you could use validation groups like Stefan mentioned.

a!localVariables(
  local!action,
  local!otherField,
  local!comment,
  {
    a!textField(
      label: "Any other required Field",
      value: local!otherField,
      saveInto: local!otherField,
      required: true
    ),
    a!textField(
      label: "Comment",
      value: local!comment,
      saveInto: local!comment,
      required: true,
      validationGroup: "REJECT"
    ),
    a!buttonArrayLayout(
      buttons: {
        a!buttonWidget(
          label: "Reject",
          style: "OUTLINE",
          value: "REJECT",
          saveInto: local!action,
          submit: true,
          validate: true,
          validationGroup: "REJECT"
        ),
        a!buttonWidget(
          label: "Approve",
          style: "SOLID",
          value: "APPROVE",
          saveInto: local!action,
          submit: true,
          validate: true,
          validationGroup: "APPROVE"
        )
      }
    )
  }
)

February 9, 2025

Thanks, everyone! The validation group works. It's been over a year since I last worked with Appian, so I'm relearning and brushing up on it.

stefanhelzle0001
February 9, 2025

Welcome back :-)