Validations button specific

Certified Associate Developer

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
      )
    }
  )

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    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"
            )
          }
        )
      }
    )

Reply
  • +1
    Certified Lead Developer

    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"
            )
          }
        )
      }
    )

Children
No Data