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 emptyCode 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 ) } )
cancel
true
false
ri!cancel
false, and still throws validation for approve button if comments is emptyCode 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 ) } )
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
Did you had a look at validation groups?
As suggested by Stefan Helzle , 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
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" ) } ) } )
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.
Welcome back :-)