Condition based validation

I need to validate the checkboxes when the submit button is clicked, based on a specific condition. There are four checkboxes, and before submitting the form, the user must check at least one. However, instead of using FormLayout, I’ve created the form using CardLayout and local variables. I’m looking for suggestions on how to improve or streamline this approach.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Using a formLayout or cardLayout should have no bearing on the outcome. If you could share the code, it would help.

  • a!localVariables(
    {
    a!boxLayout(
    label: "Business Risk Acceptance",
    contents: {
    a!boxLayout(
    label: "I am requesting a Business Risk Acceptance because I HAVE NOT completed the following (at least one box must be selected)",
    contents: {
    a!sideBySideLayout(
    items: {
    a!sideBySideItem(
    item: a!checkboxField(
    choiceLabels: {
    "Two Valid Government IDs (1 must contain photo) – Photo ID not retained for audit purposes"
    },
    choiceValues: {
    "Two Valid Government IDs (1 must contain photo) – Photo ID not retained for audit purposes"
    },
    label: "",
    value: local!docRequiredGovId,
    saveInto: local!docRequiredGovId,
    validations: if(
    a!isNotNullOrEmpty(local!docRequiredGovId),
    {},
    "At least one option must be selected."
    )
    )
    ),
    a
    }
    ),
    a!sideBySideLayout(
    items: {
    a!sideBySideItem(
    item: a!checkboxField(
    choiceLabels: {
    "Copy of 2 Valid Government IDs (optional)"
    },
    choiceValues: {
    "Copy of 2 Valid Government IDs (optional)"
    },
    label: "",
    value: local!docOptionalGovId,
    saveInto: local!docOptionalGovId,
    validations: if(
    a!isNotNullOrEmpty(local!docOptionalGovId),
    {},
    "At least one option must be selected."
    )
    )
    ),

    }
    ),
    a!sideBySideLayout(
    items: {
    a!sideBySideItem(
    item: a!checkboxField(
    choiceLabels: {
    "Consent Form and Security Regulations"
    },
    choiceValues: {
    "Consent Form and Security Regulations",

    },
    label: "",
    value: local!docConsentForm,
    saveInto: local!docConsentForm,
    validations: if(
    a!isNotNullOrEmpty(local!docConsentForm),
    {},
    "At least one option must be selected."
    )
    )
    ),

    }
    ),
    a!sideBySideLayout(
    items: {
    a!sideBySideItem(
    item: a!checkboxField(
    choiceLabels: { "ID Verification" },
    choiceValues: { "ID Verification", },
    label: "",
    value: local!docIdVerification,
    saveInto: local!docIdVerification,
    validations: if(
    a!isNotNullOrEmpty(local!docIdVerification),
    {},
    "At least one option must be selected."
    )
    )
    ),

    }
    ),
    a!sideBySideLayout(
    items: {
    a!sideBySideItem(
    item: a!checkboxField(
    choiceLabels: { "Criminal Record Check Report(s)" },
    choiceValues: { "Criminal Record Check Report(s)", },
    label: "",
    value: local!docRequiredCriminalCheck,
    saveInto: local!docRequiredCriminalCheck,
    validations: if(
    a!isNotNullOrEmpty(local!docRequiredCriminalCheck),
    {},
    "At least one option must be selected."
    )
    )
    ),

    }
    ),
    a!sideBySideLayout(
    items: {
    a!sideBySideItem(
    item: a!checkboxField(
    choiceLabels: { "Other" },
    choiceValues: { "Other", },
    label: "",
    value: local!docOther,
    saveInto: local!docOther,
    validations: if(
    a!isNotNullOrEmpty(local!docOther),
    {},
    "At least one option must be selected."
    )
    )
    ),

    }
    )
    },
    isCollapsible: true
    )

    },
    showWhen: not(ri!readonly),
    isCollapsible: true
    ),
    a!richTextDisplayField(),

    a!buttonLayout(
    primaryButtons: a!buttonWidget(
    label: "Submit",
    saveinto:{}
    submit: true,
    style: "SOLID",
    loadingIndicator: true,
    validate: a!validationMessage(
    message: "Invalid",
    showWhen: or(
    a!isNotNullOrEmpty(local!docRequiredGovId),
    a!isNotNullOrEmpty(local!docConsentForm),
    a!isNotNullOrEmpty(local!idVerification),
    a!isNotNullOrEmpty(local!docRequiredCriminalCheck),
    a!isNotNullOrEmpty(local!docOther)
    ),
    validateAfter: "SUBMIT"
    )
    ),
    secondaryButtons: a!buttonWidget(
    label: "Cancel",
    value: true,
    saveInto: { ri!cancel },
    submit: true,
    style: "OUTLINE",
    validate: false
    ),
    showWhen: not(ri!readonly)
    )
    }
    )

  • I added a section to use the "validations" parameter and be able to place the message you require when clicking on "SUBMIT". Refer the code below. Also you can use   suggestion as posible solution.

    {
        a!boxLayout(
          label: "Business Risk Acceptance",
          contents: {
            a!boxLayout(
              label: "I am requesting a Business Risk Acceptance because I HAVE NOT completed the following (at least one box must be selected)",
              contents: {
                a!sectionLayout(
                  contents: {
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: {
                              "Two Valid Government IDs (1 must contain photo) – Photo ID not retained for audit purposes"
                            },
                            choiceValues: {
                              "Two Valid Government IDs (1 must contain photo) – Photo ID not retained for audit purposes"
                            },
                            label: "",
                            value: local!docRequiredGovId,
                            saveInto: local!docRequiredGovId,
                            validations: if(
                              a!isNotNullOrEmpty(local!docRequiredGovId),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        )
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: {
                              "Copy of 2 Valid Government IDs (optional)"
                            },
                            choiceValues: {
                              "Copy of 2 Valid Government IDs (optional)"
                            },
                            label: "",
                            value: local!docOptionalGovId,
                            saveInto: local!docOptionalGovId,
                            validations: if(
                              a!isNotNullOrEmpty(local!docOptionalGovId),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: {
                              "Consent Form and Security Regulations"
                            },
                            choiceValues: {
                              "Consent Form and Security Regulations",
    
                            },
                            label: "",
                            value: local!docConsentForm,
                            saveInto: local!docConsentForm,
                            validations: if(
                              a!isNotNullOrEmpty(local!docConsentForm),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: { "ID Verification" },
                            choiceValues: { "ID Verification", },
                            label: "",
                            value: local!docIdVerification,
                            saveInto: local!docIdVerification,
                            validations: if(
                              a!isNotNullOrEmpty(local!docIdVerification),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: { "Criminal Record Check Report(s)" },
                            choiceValues: { "Criminal Record Check Report(s)", },
                            label: "",
                            value: local!docRequiredCriminalCheck,
                            saveInto: local!docRequiredCriminalCheck,
                            validations: if(
                              a!isNotNullOrEmpty(local!docRequiredCriminalCheck),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: { "Other" },
                            choiceValues: { "Other", },
                            label: "",
                            value: local!docOther,
                            saveInto: local!docOther,
                            validations: if(
                              a!isNotNullOrEmpty(local!docOther),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    )
                  },
                  validations: a!validationMessage(
                    message: "Invalid",
                    showWhen: and(
                      a!isNullOrEmpty(local!docRequiredGovId),
                      a!isNullOrEmpty(local!docConsentForm),
                      a!isNullOrEmpty(local!idVerification),
                      a!isNullOrEmpty(local!docRequiredCriminalCheck),
                      a!isNullOrEmpty(local!docOther)
                    ),
                    validateAfter: "SUBMIT"
                  )
                )
              },
              isCollapsible: true
            )
          },
          showWhen: not(ri!readonly),
          isCollapsible: true
        ),
        a!richTextDisplayField(),
        a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Submit",
            saveinto:{},
            submit: true,
            style: "SOLID",
            loadingIndicator: true,
            validate: true,
            /*validate: a!validationMessage(*/
              /*message: "Invalid",*/
              /*showWhen: or(*/
                /*a!isNotNullOrEmpty(local!docRequiredGovId),*/
                /*a!isNotNullOrEmpty(local!docConsentForm),*/
                /*a!isNotNullOrEmpty(local!idVerification),*/
                /*a!isNotNullOrEmpty(local!docRequiredCriminalCheck),*/
                /*a!isNotNullOrEmpty(local!docOther)*/
              /*),*/
              /*validateAfter: "SUBMIT"*/
            /*)*/
          ),
          secondaryButtons: a!buttonWidget(
            label: "Cancel",
            value: true,
            saveInto: { ri!cancel },
            submit: true,
            style: "OUTLINE",
            validate: false
          ),
          showWhen: not(ri!readonly)
        )
      }


Reply
  • I added a section to use the "validations" parameter and be able to place the message you require when clicking on "SUBMIT". Refer the code below. Also you can use   suggestion as posible solution.

    {
        a!boxLayout(
          label: "Business Risk Acceptance",
          contents: {
            a!boxLayout(
              label: "I am requesting a Business Risk Acceptance because I HAVE NOT completed the following (at least one box must be selected)",
              contents: {
                a!sectionLayout(
                  contents: {
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: {
                              "Two Valid Government IDs (1 must contain photo) – Photo ID not retained for audit purposes"
                            },
                            choiceValues: {
                              "Two Valid Government IDs (1 must contain photo) – Photo ID not retained for audit purposes"
                            },
                            label: "",
                            value: local!docRequiredGovId,
                            saveInto: local!docRequiredGovId,
                            validations: if(
                              a!isNotNullOrEmpty(local!docRequiredGovId),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        )
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: {
                              "Copy of 2 Valid Government IDs (optional)"
                            },
                            choiceValues: {
                              "Copy of 2 Valid Government IDs (optional)"
                            },
                            label: "",
                            value: local!docOptionalGovId,
                            saveInto: local!docOptionalGovId,
                            validations: if(
                              a!isNotNullOrEmpty(local!docOptionalGovId),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: {
                              "Consent Form and Security Regulations"
                            },
                            choiceValues: {
                              "Consent Form and Security Regulations",
    
                            },
                            label: "",
                            value: local!docConsentForm,
                            saveInto: local!docConsentForm,
                            validations: if(
                              a!isNotNullOrEmpty(local!docConsentForm),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: { "ID Verification" },
                            choiceValues: { "ID Verification", },
                            label: "",
                            value: local!docIdVerification,
                            saveInto: local!docIdVerification,
                            validations: if(
                              a!isNotNullOrEmpty(local!docIdVerification),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: { "Criminal Record Check Report(s)" },
                            choiceValues: { "Criminal Record Check Report(s)", },
                            label: "",
                            value: local!docRequiredCriminalCheck,
                            saveInto: local!docRequiredCriminalCheck,
                            validations: if(
                              a!isNotNullOrEmpty(local!docRequiredCriminalCheck),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    ),
                    a!sideBySideLayout(
                      items: {
                        a!sideBySideItem(
                          item: a!checkboxField(
                            choiceLabels: { "Other" },
                            choiceValues: { "Other", },
                            label: "",
                            value: local!docOther,
                            saveInto: local!docOther,
                            validations: if(
                              a!isNotNullOrEmpty(local!docOther),
                              {},
                              "At least one option must be selected."
                            )
                          )
                        ),
    
                      }
                    )
                  },
                  validations: a!validationMessage(
                    message: "Invalid",
                    showWhen: and(
                      a!isNullOrEmpty(local!docRequiredGovId),
                      a!isNullOrEmpty(local!docConsentForm),
                      a!isNullOrEmpty(local!idVerification),
                      a!isNullOrEmpty(local!docRequiredCriminalCheck),
                      a!isNullOrEmpty(local!docOther)
                    ),
                    validateAfter: "SUBMIT"
                  )
                )
              },
              isCollapsible: true
            )
          },
          showWhen: not(ri!readonly),
          isCollapsible: true
        ),
        a!richTextDisplayField(),
        a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Submit",
            saveinto:{},
            submit: true,
            style: "SOLID",
            loadingIndicator: true,
            validate: true,
            /*validate: a!validationMessage(*/
              /*message: "Invalid",*/
              /*showWhen: or(*/
                /*a!isNotNullOrEmpty(local!docRequiredGovId),*/
                /*a!isNotNullOrEmpty(local!docConsentForm),*/
                /*a!isNotNullOrEmpty(local!idVerification),*/
                /*a!isNotNullOrEmpty(local!docRequiredCriminalCheck),*/
                /*a!isNotNullOrEmpty(local!docOther)*/
              /*),*/
              /*validateAfter: "SUBMIT"*/
            /*)*/
          ),
          secondaryButtons: a!buttonWidget(
            label: "Cancel",
            value: true,
            saveInto: { ri!cancel },
            submit: true,
            style: "OUTLINE",
            validate: false
          ),
          showWhen: not(ri!readonly)
        )
      }


Children