Disable submit button via client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 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
3 hours ago
If the record should not be submitted if this field is blank and the field is updated by a different script/process you can either not allow this field to be updated to blank by that process, so prevent the update upstream, or return 'false' in an onSubmit Client Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Since the field is hidden, what is changing the field to trigger your onChange Client Script? This use case is not making a lot of sense.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
that's not recommended approach.
you can use onSubmit script and stop form submission based on field value
💡 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
