Multiple Validation group on a same field

Certified Senior Developer

Can I have multiple validation groups for the one sail component? 

Considering I have Field A, Field B, and 3 buttons. Field A is mandatory for 2 buttons Button_A and Button_B. How to achieve this?

{
    a!columnsLayout(
      columns: {
        a!columnLayout(
          contents: {
            a!textField(
              label: "Name",
              labelPosition: "ABOVE",
              saveInto: {},
              required: true,
              refreshAfter: "UNFOCUS",
              validationGroup:  
                {
                  "Button_A",
                  "Button_B"
                }
              
            ),
            a!textField(
              label: "Mobile Number",
              labelPosition: "ABOVE",
              saveInto: {},
              required: true(),
              refreshAfter: "UNFOCUS",
              validations: {},
              validationGroup: "Button B"
            )
          }
        ),
        
      }
    ),
    a!buttonArrayLayout(
      buttons: {
        a!buttonWidget(
          label: "Button A",
          style: "NORMAL",
          submit: true(),
          validationGroup: "Button_A"
        ),
        a!buttonWidget(
          label: "Button B",
          style: "NORMAL",
          submit: true(),
          validationGroup: "Button_B"
        ),
        a!buttonWidget(
          label: "Button C",
          style: "NORMAL",
          submit: true(),
          validationGroup: "Button_C"
        )
      },
      align: "START"
    )
}

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    Hello,

    I have a different case. 

    I have a form with two buttons with validate: true(), and each with a different validationGroup.

    One is a save button which only requires one field.

    The other one is a submit button which requires all of the fields to be filled.

    Therefore, there is a field (multipleDropdownField) that is required for both buttons.

    The problem is that the "validationGroup" parameter of the multipleDropdown field only allows a Text and not an array of Text, and the value of the button (ri!buttonValue) cannot be used in an "if" statement because when the buttons are clicked, ri!buttonValue does not change unless the validations are satisfied. 

    I hope I am explaining and I hope you can help me with my problem.

    Thanks in advance.

  • 0
    Certified Lead Developer
    in reply to Fernando Briones

    I think you cannot use validation groups to solve this challenge.

    Did you consider to just keep both buttons disabled until that common field has a value, and then let the normal validation take over?

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    I was so blinded trying my approach, that I did not even think about the one you just proposed. That is really smart and I appreciate your idea and the support! I will implement it. 

  • +1
    Certified Senior Developer
    in reply to Fernando Briones

    We can configure the multiple validation groups in the same field.

    For example, consider button 1 validation group as TESTONE and button 2 validation as TESTTWO. Then in the field(multipleDropdownField) configure the validation group as "TESTONE TESTTWO"

  • +1
    Certified Lead Developer
    in reply to Keerthanakr

    Great to know! Another completely undocumented feature.

    A small test:

    {
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!textField(
                label: "Text (A)",
                labelPosition: "ABOVE",
                saveInto: {},
                refreshAfter: "UNFOCUS",
                required: true,
                validations: {},
                validationGroup: "A"
              )
            }
          ),
          a!columnLayout(
            contents: {
              a!textField(
                label: "Text (A+B)",
                labelPosition: "ABOVE",
                saveInto: {},
                refreshAfter: "UNFOCUS",
                required: true,
                validations: {},
                validationGroup: "A B"
              )
            }
          ),
          a!columnLayout(
            contents: {
              a!textField(
                label: "Text (B+C)",
                labelPosition: "ABOVE",
                saveInto: {},
                refreshAfter: "UNFOCUS",
                required: true,
                validations: {},
                validationGroup: "B C"
              )
            }
          ),
          a!columnLayout(
            contents: {
              a!textField(
                label: "Text (D)",
                labelPosition: "ABOVE",
                saveInto: {},
                refreshAfter: "UNFOCUS",
                required: true,
                validations: {},
                validationGroup: "D"
              )
            }
          ),
        }
      ),
      a!buttonArrayLayout(
        buttons: {
          a!buttonWidget(
            label: "A",
            style: "OUTLINE",
            validate: true,
            validationGroup: "A"
          ),
          a!buttonWidget(
            label: "B",
            style: "OUTLINE",
            validate: true,
            validationGroup: "B"
          ),
          a!buttonWidget(
            label: "C",
            style: "OUTLINE",
            validate: true,
            validationGroup: "C"
          ),
          a!buttonWidget(
            label: "A+D (Does not work)",
            style: "OUTLINE",
            validate: true,
            validationGroup: "A D"
          ),
        },
        align: "START",
        marginBelow: "NONE"
      ),
    }