how to show the different required message for the same field?

Certified Senior Developer

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

Parents
  • 0
    Certified Lead Developer

    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.

Reply
  • 0
    Certified Lead Developer

    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.

Children