How to skip required fields but not the custom validations of fields with a press of button?

I have a form which has a secondary button which is supposed to skip required fields but not the custom validation of fields after pressing that button. Is there a way to do this?

  Discussion posts and replies are publicly visible

Parents
  • Hello Mohits

    Look at the link shared by Shiva. One of the not well documented but powerful this mentioned in that thread is that you can actually use the validationGroup for multiple buttons just like this :

    validationGroup:"button1 button2"

    take a look at this example It might help you

    load(
      local!button1,
      local!button2,
      local!text1,
      local!text2,
      a!formLayout(
        contents: a!columnsLayout(
          columns: {
            a!columnLayout(
              a!textfield(
                label: "text1",
                required: true,
                value: local!text1,
                saveInto: local!text1,
                validationGroup: "button1"/*<<-- NOTE this*/
                
              )
            ),
            a!columnLayout(
              a!textfield(
                label: "texx2",
                required: true,
                value: local!text2,
                saveInto: local!text2,
                validationGroup: "button1 button2"/*<<-- NOTE this*/
                
              )
            )
          }
        ),
        buttons: a!buttonlayout(
          primaryButtons: {
            a!buttonWidgetSubmit(
              label: "button1",
              value: true,
              saveInto: local!button1,
              /*skipvalidation: true*//*<<-- NOTE this*/
              validationGroup: "button1"/*<<-- NOTE this*/
              
            ),
            a!buttonWidgetSubmit(
              label: "button2",
              value: false,
              saveInto: local!button2,
              validationGroup: "button2"/*<<-- NOTE this*/
              
            )
          }
        )
      )
    )

     

    Jose

  • Hi Jose,

    I could use validationgroups if both required= true() and custom validations are not used for the same fields.

    As for my case all the fields are mandatory in the interface and also almost all have a validation for their length of 255 chars.

    This is my primary requirement:

    1) There is a button to save which is a secondary button for which i want to skip the required = true() validation but not the custom validation of length<=255 chars.

    2) I want all the validation, required=true() and length validation to trigger when the submit primary button is triggered.

    I'm unable to satisfy the 1) requirement using validationgroups because the same field has both the validations

  • 0
    Certified Lead Developer
    in reply to mohitshah

    Hi mohits0001,

    Try the below code. Here the required validation is added to the section layout  on SUBMIT

    a!formLayout(
      label: "Allow Save",
      contents: {
        a!sectionLayout(
          contents: a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!textField(
                    label: "Name *",
                    labelPosition: "ABOVE",
                    value: ri!name,
                    saveInto: ri!name,
                    refreshAfter: "UNFOCUS",
                    validations: {
                      if(
                        len(
                          ri!name
                        ) > 50,
                        "Name cannot have more than 50 Characters",
                        ""
                      )
                    }
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!textField(
                    label: "Phone Number *",
                    labelPosition: "ABOVE",
                    value: ri!phoneNumber,
                    saveInto: ri!phoneNumber,
                    refreshAfter: "UNFOCUS",
                    validations: {
                      if(
                        len(
                          ri!phoneNumber
                        ) > 10,
                        "Phone Number cannot have more than 10 Characters",
                        ""
                      )
                    }
                  )
                }
              )
            }
          ),
          validations: {
            a!validationMessage(
              message: "Name is required to submit",
              validateAfter: "SUBMIT",
              showWhen: or(
                isnull(
                  ri!name
                ),
                trim(
                  ri!name
                ) = ""
              )
            ),
            a!validationMessage(
              message: "Phone Number is required to submit",
              validateAfter: "SUBMIT",
              showWhen: or(
                isnull(
                  ri!phoneNumber
                ),
                trim(
                  ri!phoneNumber
                ) = ""
              )
            )
          },
          validationGroup: "SUBMIT"
        )
      },
      buttons: a!buttonLayout(
        primaryButtons: {
          a!buttonWidgetSubmit(
            label: "Submit",
            validationGroup: "SUBMIT",
            style: "PRIMARY"
          ),
          a!buttonWidgetSubmit(
            label: "Save",
            saveInto: {},
            style: "NORMAL"
          )
        }
      )
    )

Reply
  • 0
    Certified Lead Developer
    in reply to mohitshah

    Hi mohits0001,

    Try the below code. Here the required validation is added to the section layout  on SUBMIT

    a!formLayout(
      label: "Allow Save",
      contents: {
        a!sectionLayout(
          contents: a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!textField(
                    label: "Name *",
                    labelPosition: "ABOVE",
                    value: ri!name,
                    saveInto: ri!name,
                    refreshAfter: "UNFOCUS",
                    validations: {
                      if(
                        len(
                          ri!name
                        ) > 50,
                        "Name cannot have more than 50 Characters",
                        ""
                      )
                    }
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!textField(
                    label: "Phone Number *",
                    labelPosition: "ABOVE",
                    value: ri!phoneNumber,
                    saveInto: ri!phoneNumber,
                    refreshAfter: "UNFOCUS",
                    validations: {
                      if(
                        len(
                          ri!phoneNumber
                        ) > 10,
                        "Phone Number cannot have more than 10 Characters",
                        ""
                      )
                    }
                  )
                }
              )
            }
          ),
          validations: {
            a!validationMessage(
              message: "Name is required to submit",
              validateAfter: "SUBMIT",
              showWhen: or(
                isnull(
                  ri!name
                ),
                trim(
                  ri!name
                ) = ""
              )
            ),
            a!validationMessage(
              message: "Phone Number is required to submit",
              validateAfter: "SUBMIT",
              showWhen: or(
                isnull(
                  ri!phoneNumber
                ),
                trim(
                  ri!phoneNumber
                ) = ""
              )
            )
          },
          validationGroup: "SUBMIT"
        )
      },
      buttons: a!buttonLayout(
        primaryButtons: {
          a!buttonWidgetSubmit(
            label: "Submit",
            validationGroup: "SUBMIT",
            style: "PRIMARY"
          ),
          a!buttonWidgetSubmit(
            label: "Save",
            saveInto: {},
            style: "NORMAL"
          )
        }
      )
    )

Children
No Data