How to make a field mandatory on submit based on the field not visible on form on submit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2022 07:48 AM
How to make a field mandatory on submit based on the field not visible on form on submit but gets auto populated based on selections made through a different client script
We are trying to set Parent field mandatory based on the value on 'Type' field, but the 'Type' field is hidden on submit. Based on the below links selected the value for 'Type' field will be populated
I tried onSubmit client script, but it did not work. Parent field is becoming mandatory for all types. Any help is highly appreciated.
var type = g_form.getValue('type');
if ((type != 'Site') || (type != 'Region')) {
g_form.setMandatory('parent', 'true');
var msg = getMessage("Parent field is mandatory, please fill and submit.");
g_form.showFieldMsg("parent", msg, "error");
return false;
}
Thanks,
J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 07:45 PM
Also making fields mandatory onSubmit is a bad UI design/behavior.
Fields should be mandatory when the conditions for it are met, so that by the time the user hits Submit, it should be clear to the user what fields must be filled in - to avoid hitting Submit in vain.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2023 09:54 PM
Hello @Community Alums
I would suggest to create a UI Policy with
Condition : Type is not Site AND Type is not Region
Reverse if false : checked
Global : checked
on load: checked
Under UI Policy Actions:
Field: Parent, Read only: leave alone, Mandatory: true, Display: leave alone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 05:06 AM
Hi Mahendra,
I tried creating UI policy but it did not work, reason could be the field type is glide_list.
I followed below process to get the client script working
1. I have deactivated existing client script to hide the filed 'Type' on load
2. Created another onLoad client script to make parent field mandatory for the new record and set the type field readonly
function onLoad() {
var seeType = g_form.getValue('type');
if (g_form.isNewRecord()) {
if ((seeType == '68038ff697454d10769b36b3f153afd5') || (seeType == '64f24f3a97454d10769b36b3f153af69')) {
g_form.setMandatory('parent', false);
g_form.setReadOnly('type', true);
}
else {
g_form.setMandatory('parent', true);
g_form.setReadOnly('type', true);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 06:38 AM - edited 01-04-2023 06:39 AM
If a field is just hidden that does not mean (from the p.o.v. of GlideForm) that that field is not on the form.
But if the field type is glide list, the comparison operator should not be ==. You should use
seeType.indexOf('68038ff697454d10769b36b3f153afd5') > -1
and
seeType.indexOf('64f24f3a97454d10769b36b3f153af69') > -1
otherwise you could run into false negatives. E.g. the type field contains either of the above mentioned sys_ids but also other sys_ids as a glide list field contains as value a comma separated list of sys_ids.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 06:55 AM
That said, creating a UI Policy for a Glide list field should not be a problem - it should work. Could you take a screen-shot of the UI Policy you tried to create?