Disable submit button via client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have an onchange client script and I need the submit button to be disabled if the field is empty. I tried this method, but it's not working. Could someone help me disable this field when it's empty?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Se o campo estiver vazio, desabilita o Submit
if (!newValue || newValue.trim() === '') {
g_form.setSubmitEnabled(false);
} else {
// Se houver imagem, habilita o Submit
g_form.setSubmitEnabled(true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I think this approach is all wrong. First off, you need to use actual g_form methods that exist, you can't make up new names
Since you're referring to a 'submit' button, is this a new record on a form? In that case the field in question, as all fields, will be empty to start so it may never change.
A simple out of box solution for what you're trying to accomplish is to make the field mandatory, then Submit or Update/Save will not be allowed if there is not a value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Unfortunately, it's not possible to make this field mandatory because it needs to remain hidden. When I make it mandatory, it ends up becoming visible to the applicant.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
if field is hidden on form then how it matters to user if it's empty
user can't fill it and it's annoying to stop them for something which they were not supposed or allowed to edit.
It's not good user experience.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
59m ago
This field is hidden because it receives the sys ID of a record, and I use this record in other scripts to load other information.
