- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 06:27 AM
I want to make a field mandatory in an UI Page and by using required tag it is not working. Any workaround? maybe some javascript code or any other thing?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 11:39 PM - edited ‎03-18-2025 11:41 PM
1 way is to use client script in UI page
Other way is check how OOB UI pages from ServiceNow is being done, check that code.
refer these link if that helps
creating a mandatory field in ui page?
Make UI Page Text area mandatory
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2025 03:01 AM
Hi @SamiranD Can you try this with your field-
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div style="padding:21px">
<table>
<tr>
<td style="width:25%">
<g:form_label>
Text Field
</g:form_label>
</td>
<td style="width:60%">
<textarea id="text_field" name="text_field" class="form-control" spellcheck="true" rows="6" cols="65" required="required"></textarea> <!-- required attribute is not working -->
<span style='color: red;' id="error_msg" class="outputmsg_text"></span>
</td>
</tr>
</table>
</div>
<div style="padding:5px;float:right">
<g:dialog_buttons_ok_cancel style="padding:5px;margin-right:10px" ok_id="submitData" ok="return OnSubmit()" oh_type="button" ok_text="${gs.getMessage('Submit')}" ok_style_class="btn btn-primary"/>
</div>
</j:jelly>
and client script -
function OnSubmit() {
var changeDetails = gel('text_field').value;
changeDetails = changeDetails.toString();
if (changeDetails == ' ') {
$j('#error_msg').html(getMessage('Please fill the field'));
gel('error_msg').show();
return false;
} else {
GlideDialogWindow.get().destroy();
window.location.reload();
}
}