How to make macro mandatory/required using js?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 08:33 AM
I'm having trouble with scripting in the Macro I'm working with. I would like to make a field mandatory/required. The user must fill out the field before the form can be submitted. In the macro there HTML that defines the fields and input fields. Here is what I coded, but the script is not taking effect, I am able to submit when the field is blank (which is what I'm trying to fix)
<script>
const input = document.querySelectorAll("#accprefix, #accName").value;
input.setAttribute("required", "");
document.getElementsByClass("accountName").onSubmit = function() {
if(document.getElementById("accprefix").value = "" || document.getElementById("accName").value = "" )
{
alert("Account Name is required for submission");
}
};
</script>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2022 09:13 AM
Hello Janna,
Here's how I tackle these types of requirements:
- create the html fields on macro
- Add the macro on SN form
- create a hidden field that acts as a true/false flag to indicate the required fields on the macro are filled/unfilled (This would default to false)
- Use an onchange event handler on the HTML field such that when its is filled a function sets the hidden field to true using g_form method.
- Have an onsubmit script on the SN form to check if the hidden field is false, if so, prevent submission