Using Validation Groups When Certain Buttons Are Clicked

I am trying to use validation groups to apply a validation only when certain buttons are clicked. I grabbed an example on forum that demonstrated having a field be required only when one of two buttons are clicked. I added validation to the same component, but the validation is displayed regardless of which button is clicked. Is there any way to make this work? See attached sample code.

validationGroupExample.txt

OriginalPostID-227120

OriginalPostID-227120

  Discussion posts and replies are publicly visible

  • Hi Scott , You can use Form layout validation and Validation Group, below sample code
    load(
    local!a,
    local!b,
    local!text1,
    local!text2,
    a!formLayout(
    validationGroup:"buttonA",
    validations:if(len(local!text1)>1,a!validationMessage(message:"Too Many Characters",validateAfter:"SUBMIT"),{}),
    firstColumnContents: {

    a!textField(
    label: "Conditionally Required",
    required: true,
    requiredMessage: "This field is required because you clicked Button A!",
    validationGroup: "buttonA",
    value: local!text1,
    saveInto: local!text1
    ),
    a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Button A",
    validate: true,
    validationGroup: "buttonA",
    value: "Button A!",
    saveInto: local!a
    ),
    a!buttonWidget(
    label: "Button B",
    validate: true,
    value: "Button B!",
    saveInto: local!b
    )
    }
    )
    }
    )
    )
  • @scott189,

    This also one of the way to do the validation for your requirement
    load(
    local!a,
    local!b,
    local!text1,
    local!text2,
    a!formLayout(
    firstColumnContents: {
    a!textField(
    label: "Conditionally Required",
    required: true,
    requiredMessage: "This field is required because you clicked Button A!",
    validationGroup: "buttonA",
    validations:if(local!a="Button A!",{if(len(local!text1)>1,"Too Many Characters",{})},{}),
    value: local!text1,
    saveInto: local!text1
    ),

    a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Button A",
    validate: true,
    validationGroup: "buttonA",
    value: "Button A!",
    saveInto: local!a
    ),
    a!buttonWidget(
    label: "Button B",
    validate: true,
    value: "Button B!",
    saveInto: local!b
    )
    }
    )
    }/*,
    validations:if(local!a="Button A!",{if(len(local!text1)>1,"Too Many Characters",{})},{})*/
    )
    )
  • If you want to place in form validation or within the component