Welcome to an article on ‘Pre-Save Action on Document Libraries in SharePoint 2013 and Office 365.’ We developers face an issue when our client wants to have an action done on a document library on a save click.
Document Library uploads the document, and to validate something on the save click is tricky as the save by passes the validation and gets saved.
Solution:
The solution to do any JavaScript validation is Pre Save action. So here is what you need to do.
- Open your Document Library
- Under the ‘Library’tab , click on the Form Web Parts.

- Choose Default Edit Form, you will see the screen below.

- Click on Add a Web Part,

- Choose Script Editor, under the Media and Content Web part.

- Click on Edit Snippet, you will see the screen below.

- Use the code below and click Ok.
Code:
a. Use the function PreSaveAction() and paste your validation under the function on the code.- <script src="/jquery-1.8.3.min.js" type="text/javascript"></script>
- <script src="/jquery.SPServices-0.7.2.min.js" type="text/javascript"></script>
- <script type"text/javascript">
- $(document).ready(function()
- {
- });
- function PreSaveAction()
- {
- }
- </script>
b. Before saving document library the code will check your validation and will get saved.
Doesn’t it solve a lot of queries related to document libraries functions? Keep learning!
Read more articles on SharePoint:

Sarah (MT)Posted Dec 7, 2018, 10:09 AM
I am pasting a simple alert in the presave to see if its being triggered but it's not..... it is triggered on the edit form (which makes sense) but i want it on the new form... how can i achieve this pls?
Humayun Kabir MamunPosted Mar 9, 2016, 11:18 PM
Nice...
Sagar PardeshiPosted Mar 9, 2016, 10:12 AM
What is the difference between PreSaveAction() and PreSaveItem() on SharePoint ? can plz reply
Prashant VermaPosted Mar 9, 2016, 10:09 AM
nice
Mohammed IbrahimPosted Mar 9, 2016, 9:23 AM
nice
Vignesh ManiPosted Mar 9, 2016, 5:16 AM
Nice