1

I have created a new webpart page, in this page inserted content editor and my list web part e.g. employee list with latest SharePoint Online version. Then, in the content editor I have entered below script:

<script src="https://abc.sharepoint.com/sites/cds/SiteAssets/jquery-3.1.1.min.js"></script>
<script type="text/javascript>

 var j = jQuery.noConflict(); 

function PreSaveItem()
{  
debugger; 
   if ("function"==typeof(PreSaveAction))
   {
      return PreSaveAction();
   }
   return true;
}

 function PreSaveAction() { 
debugger;
 var txtTitle = j(":input[title='Title']").val(); 
   alert(txtTitle);
   if(txtTitle == ''){        
   alert("Please enter a title");          
   return false;
}
else{
   return true;
    }
}
</script>

However, both the functions PreSaveAction and PreSaveItem are not firing...

2 Answers 2

1

You've missed an " at the end of type="text/javascript in line 2.

After fixing that both events fire in my environment (SharePoint Online).

Although this might just be a copy & paste error in the question, it makes sense to verify that the code you've entered appears on the page as you wrote it. The content-editor might alter code you entered in the "Edit Source" dialog. You can double-check by clicking "Edit Source" again after you've closed it or triple-check by inspecting the HTML returned by the server when opening the new-/edit-form.

0

In SharePoint PreSaveItem function is called when onClick event handler is fired for Save button in List Forms. PreSaveAction function from another hand, allows to override behavior for a Save button.

If you want to do validation for list form, you need add the custom code to list form(new/edit form).

1
  • I have added the custom code to list form(new/edit form), but functions PreSaveAction and PreSaveItem still do not fired. Jan 9, 2018 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.