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 Senior Developer

    As suggested by  , 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

Reply
  • +1
    Certified Senior Developer

    As suggested by  , 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

Children
No Data