How to Make Attachments Mandatory in SharePoint List?

Requirement: In a SharePoint list, make the attachment required field!

Make attachments mandatory in the SharePoint list:

While creating a Document library with metadata columns is one option, the requirement is only to make the attachments mandatory in SharePoint list forms. To make attachments mandatory in the SharePoint list, we can use simple JavaScript. Add content editor or script editor web part on “NewForm.aspx” just below SharePoint list form web part, and then place the below code in it!

JavaScript to make attachments mandatory:
Use this Javascript in script editor web part in classic experience!

<script type="text/javascript" language="javascript">

function PreSaveAction() {
if (document.getElementById('idAttachmentsRow').style.display=='none' )
  {
     alert('Attachment is Mandatory! Please attach Documents.');
     return false ;
  }
else {  return true;  }
}
</script>

And here is the script in action:

sharepoint 2013 list attachment mandatory

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

6 thoughts on “How to Make Attachments Mandatory in SharePoint List?

  • How to Make Attachments Mandatory in SharePoint List by type of file pdf only or image only?

    thanks

    Reply
  • Form Web Parts > Default New Form > Add a Web Part > Media and Content folder > Script Editor > paste javascript there. Thanks for this!

    Reply
  • I’ve been testing this solution all day and can’t get it to function. By loading js into a CEWP, I have been able to test simple things like getting “Hello World” to display on load. But when I switch to the above js code and attempt to submit my form without an attachment, it allows me to without the error message. What might I be missing? Thanks!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *