Form level validation is not triggering on Submit - 2part

I have the same problem like

"This validation is working fine when I am testing the interface. But when the interface is integrated to the process, validation doesn't trigger and form gets submitted without executing the validation.
Is there anything else that I should configure to make sure that validation gets executed before the submission of form?"  https://community.appian.com/discussions/f/user-interface/8783/form-level-validation-is-not-triggering-on-submit

load(
  local!isCustomer: true,
  local!customerDetails,
  local!showSearchResults,
  local!selectedCustomer,
  local!errorMessage,
  with(
    a!formLayout(
      label: "Test",
      validationGroup: "main",
      validations: if(
        rule!IsNotNullOrEmpty(
          local!errorMessage
        ),
        local!errorMessage,
        null
      ),
      contents: {
            a!radioButtonField(
              choiceLayout: "COMPACT",
              choiceLabels: {
                "Customer",
                "Non-Customer"
              },
              choiceValues: {
                true,
                false
              },
              value: local!isCustomer,
              saveInto: {
                local!isCustomer,
                a!save(
                  ri!bpCustomer,
                  null
                )
              }
            ),
            if(
              local!isCustomer,
              {
                a!sectionLayout(
                  contents: rule!BAE_SectionSearchCustomer(
                    showSearchResults: local!showSearchResults,
                    selectedCustomer: local!selectedCustomer
                  )
                ),
                a!buttonLayout(
                  primaryButtons: {
                    a!buttonWidgetSubmit(
                      label: "Next",
                      value: true,
                      skipValidation: false,
                      saveInto: {
                        a!save(
                          local!customerDetails,
                          rule!GetCustomerById(
                            local!selectedCustomer.CustomerID
                          )
                        ),
                        if(
                          rule!IsNotNullOrEmpty(
                            local!customerDetails
                          ),
                          {
                            a!save(
                              ri!bpCustomer,
                              ............
                              )
                            ),
                            a!save(
                              local!errorMessage,
                              null
                            )
                          },
                          a!save(
                            local!errorMessage,
                            "Something went wrong, unable to retrieve additional customer data, please try again"
                          )
                        ),
                        a!save(
                          ri!auditHistory,
                          append(
                            ri!auditHistory,
                            'type!{urn:com:appian:types:BP}BP_AuditHistory'(
                              user: loggedInUser(),
                              step: "Select Customer",
                              action: "NEXT",
                              comment: "Existing Customer",
                              timestamp: now()
                            )
                          )
                        )
                      },
                      validationGroup: "main",
                      disabled: rule!IsNullOrEmpty(
                        local!selectedCustomer
                      )
                    )
                  },
                  secondaryButtons: {
                    a!buttonWidgetSubmit(
                      label: "Cancel",
                      skipValidation: true,
                      value: true,
                      saveInto: {
                      }
                    )
                  }
                )
              },
              {
                a!sectionLayout(
                  label: "",
                  contents: {
                    a!textField(
                      value: "Then let's continue",
                      readonly: true
                    ),
                    a!buttonLayout(
                      a!buttonWidgetSubmit(
                        label: "Next",
                        value: true,
                        skipValidation: true,
                        saveInto: {
                        }
                      )
                    )
                  }
                )
              }
            )
      }
    )
  )
)

I have a form which has a form level validation which is configured to execute on Submit, using validationGroup . Attached the code. Maybe, somebody will find a mistake.

 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Yes Mainly this because  , your validation logic is depend on the variable which are getting updated in saveInto of button.

    When we click on submit button it just execute the saveInto block on submit button and and submits the form . it does not re-execute the form.

    I tried below approached and it worked.

    1. Calculate all validation messages in local variable in with

    2. Then take Boolean flag to check whether all validation are passed or not

    3. Use that flag to decide whether to make button submit-able or not

     

    Below is the sample code sniplet

    with(
      local!validation1: "Test",
      /*Put your logic if no validation return null*/
      local!validation2: "Test2",
      /*Put your logic if no validation return null*/
      local!allvalidationPass: and(
        rule!APN_isEmpty(
          local!validation1
        ),
        rule!APN_isEmpty(
          local!validation2
        )
      ),
      a!formLayout(
        contents: {
          a!textField(
            label: "test",
            value: "test",
            validations: local!validation1
          ),
          a!textField(
            label: "test",
            value: "test",
            validations: local!validation2
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(
            submit: local!allvalidationPass
          )
        )
      )
    )

Reply
  • 0
    Certified Lead Developer

    Yes Mainly this because  , your validation logic is depend on the variable which are getting updated in saveInto of button.

    When we click on submit button it just execute the saveInto block on submit button and and submits the form . it does not re-execute the form.

    I tried below approached and it worked.

    1. Calculate all validation messages in local variable in with

    2. Then take Boolean flag to check whether all validation are passed or not

    3. Use that flag to decide whether to make button submit-able or not

     

    Below is the sample code sniplet

    with(
      local!validation1: "Test",
      /*Put your logic if no validation return null*/
      local!validation2: "Test2",
      /*Put your logic if no validation return null*/
      local!allvalidationPass: and(
        rule!APN_isEmpty(
          local!validation1
        ),
        rule!APN_isEmpty(
          local!validation2
        )
      ),
      a!formLayout(
        contents: {
          a!textField(
            label: "test",
            value: "test",
            validations: local!validation1
          ),
          a!textField(
            label: "test",
            value: "test",
            validations: local!validation2
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(
            submit: local!allvalidationPass
          )
        )
      )
    )

Children
No Data