I have a requirement where i have a field and 3 buttons. I have to make the field required(validation should come) on click of 2 button and not required (field is not validated)on click of the third button. The third button is having submit as false(). I have tried many ways to accompalish this
1) Given condition in the "required" property of the field based on button click.
2) On "validationGroup" property i am calling a rule which decides validationGroup depending on button click.
and many more ways i have tried but nothing is working. Just wanted to know the ideal way of accomplishing this scenario?
Discussion posts and replies are publicly visible
I never really use "validationGroup" functionality since it doesn't show "required" indicators on any fields that use it, and it never seems to work like I'd hope it would. So you're not alone here.
In your example though, why can't you just set the 3rd button to have a "validate" value of False?
Do you have an example SAIL interface code you could post here and we can look at what isn't working for you and look into solutions and/or workarounds?
Thanks Mike for the reply. The 3rd button validates other fields hence i can't keep the validate property of it as false.
Can you post your code snippet here ?
I tried implementing this via 'validationGroup' and got a similar functionality working. The text field 'Field 2' doesn't show the required indicator since it is optional if the user happens to click on Button B.
a!localVariables( local!text1, local!text2, { a!sectionLayout( contents: { a!textField( label: "Field 1", required: true(), requiredMessage: "Required field validation", value: local!text1, saveInto: local!text1 ), a!textField( label: "Field 2", required: true, requiredMessage: "Optional field validation", validationGroup: "Group_1", value: local!text2, saveInto: local!text2 ), a!buttonArrayLayout( align: "END", buttons: { a!buttonWidget( label: "Button A", validate: true(), validationGroup: "Group_1" ), a!buttonWidget(label: "Button B", validate: true()) } ) } ) } )
There are other potential workarounds to this - such as, disabling a button under certain conditions, as well as form-level or section-level validations that don't fire until Submitting is attempted.
Thanks for the code snippet - can you clarify a bit more as to what behavior you're hoping to see in this case, compared to the behavior we're seeing? When I try this on my end it does seem to correctly require Field 2 when "Button A" is pressed, but not "Button B".
I was just trying to fulfill the requirement posted by the user - Srishti.
Hope this was what she was looking for.
Apologies, I wasn't looking closely enough at who posted it. Thanks for sharing - I agree this seems to follow her posted use case.
Thanks for all the help! Below is the snippet of code i am working on
a!localVariables( local!text1, local!buttonTxt, { a!sectionLayout( contents: { /*This is the only field for which i have to throw required validation when button A and B are clicked */ /*and for button x this field should be not required Also for each button validate is true because they are validating other fields as well */ a!textField( label: "Field 1", required: true(), value: local!text1, saveInto: local!text1 ), a!buttonArrayLayout( align: "END", buttons: { a!buttonWidget( label: "Button X", style: "PRIMARY", value: "ButtonX", saveInto: local!buttonTxt, validate: true(), validationGroup: "GroupX" ) } ), a!buttonArrayLayout( align: "END", buttons: { a!buttonWidget( label: "Button A", value: "ButtonA", saveInto: local!buttonTxt, submit: true(), /*Submit is true*/ validate: true(), validationGroup: "GroupA" ), a!buttonWidget( label: "Button B", style: "PRIMARY", value: "ButtonB", saveInto: local!buttonTxt, submit: true(), /*Submit is true*/ validate: true(), validationGroup: "GroupB" ) } ) } ) } )
Thanks for providing this - as I mentioned above accidentally in the wrong place, can you provide some further detail as to the behavior you're expecting to see on this form, compared to what behavior you're experiencing?