How to make filed visible and mandatory when Form button is clicked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2017 12:43 PM
Hi Team.
I want to make filed(rejected reason) Visible and make it mandatory when the 'Rejected' form button is clicked.
----------------------
Existing code for Rejected form button is clicked
When Rejected form button is clicked ..Comments button becomes mandatory.
and the code for this is
--
current.state = 'rejected';
if(!JSUtil.nil(current.comments))
current.update();
else{
gs.addErrorMessage("Comments are required when rejecting an approval");
current.state = 'requested';
current.setAbortAction(true);
}
----------------
can i add the code to above code to make my field visible and mandatory or do i need to write new UI action or something else..
Please suggest
Aarav.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2017 04:15 PM
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2020 07:59 AM
Hello Berny,
Thanks for the above solution which i was looking for.
I have one question on top of this.
Can we have a error message on top in general like " Please fill in Required fields".
This has to appear on top of the field message shown.
This top message has to show if any of the required fields is still not filled.
PLease help
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2020 08:07 AM
Hi,
Here is link for your solution.
If it Helps,please mark it as Correct and Helpful.
Warm Regards,
Milind
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2017 12:56 PM
You can also use UI policies, which is a best practice to set fields as Mandatory or ReadOnly. The UI policy can work based on the field values.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2017 12:58 PM
Regarding the client code for hiding or showing a field you can use g_form.setDisplay or g_form.setVisible
The following thread have a good description of these:
difference between setVisible() and setDisplay() on g_form?
Thanks,
Berny