Hi,
We have requirement like need to show different required message(dynamic message) for a particular field based on two different button clicks.
here are the more details like we have one comments field which is required for both the submit buttons with names like "Add More Info" and "Add More Comments" .
when the user clicks on "Add More Info" button without providing the comments then need to show the required message is like "comments required for More Information".
when the user clicks on "Add More Comments" button without providing the data to comments field then need to show the required message like "comments should not be blank"
Can some one suggest any way to achieve this...
-Ram
Discussion posts and replies are publicly visible
Hi, required messages should only show after something on the form has triggered a validation (e.g., a button with validate set to true). For example, if you test out the code below you'll see that the required message only shows after you click on the button
{ a!paragraphField( label: "Paragraph", value: "", required: true, requiredMessage: "abc" ), a!buttonArrayLayout( buttons: a!buttonWidget( label: "Button", validate: true ) ) }
This use case technically violates how buttonWidget save events work, because failed validation (i.e. for missing "required" fields) executes before the buttonWidget saveInto does. Meaning that your custom required message would not have any value by which to judge which version it should show. The best solution for this would be to restructure your form logic in such a way that your required message doesn't rely on what the value of the button click was.
Otherwise, the only working solution I know of, is to create a complex workaround utilizing local variables and conditionally setting the "submit" value of the button, and setting manual validations on the input field. This is tricky though and I'd only recommend it to seasoned SAIL developers and only when really necessary.
Hello Ramp,
I agree with Mike, the logic should not rely on the button that is pressed why don't you just add the default message or a generic.
Here is an example how the solution can be. If you have more fields then this is not going to work as is.
load( local!text: "", local!tmpButton, a!formLayout( contents: a!columnsLayout( columns: { a!columnLayout( contents: { a!paragraphField( label: "Comment" , value: local!text, saveInto: local!text, /*refreshAfter: "KEYPRESS",*/ required: not(rule!APN_isBlank(local!tmpButton)),/* < -- Note this*/ validationGroup: "submit save" ), a!richTextDisplayField(/* < -- Note this*/ showWhen: and ( not(rule!APN_isBlank(local!tmpButton)), rule!APN_isBlank(local!text) ), value:a!richTextItem( text:a!richTextItem( text:if( local!tmpButton = "save", "Please add comment on save", "Please add Note on submit" ), style: "NEGATIVE" ), style: "STRONG" ) ) } ) } ), validations: {}, buttons: a!buttonlayout( primaryButtons: { a!buttonWidget( showWhen: rule!APN_isBlank(local!text), saveInto: local!tmpButton, label: "submit Widget", value: "submit", style: "PRIMARY" ), a!buttonWidget( showWhen: rule!APN_isBlank(local!text), saveInto: local!tmpButton, label: "save Widget", value: "save", style: "SECONDARY" ), a!buttonWidgetSubmit( showWhen: not(rule!APN_isBlank(local!text)), saveInto: ri!button, validationGroup: "submit", label: "submit Submit", value: "submit", style: "PRIMARY" ), a!buttonWidgetSubmit( showWhen: not(rule!APN_isBlank(local!text)), saveInto: ri!button, label: "save Submit", value: "save", validationGroup: "save", style: "SECONDARY" ) } ) ) )
Jose