0

I've to make come check on the newform and editform in custom list. I've to check if a field has a value if an other has. I've to check if a document depending on meta already exist in an other library. If it's true i've to alert the user and ask if we replace it or not. If not we return to the form.

Maybe can i use event receiver in itemupdating and cancel but how to return to the form and display message?

how can i achieve this type of operation?

thanks

2 Answers 2

0

You can use PreSaveAction() function to do your custom validation. This function is executed once you click on the submit button. return true to submit the form or else return false to stay in the same page.

Add a js file to the page and insert the code as follows:

function PreSaveAction(){
    if($('#someid').val() == ''){
        alert('Required field'); // some custom validation
        return false;
    }else{
        return true;
    }
}
2
  • thanks i finally choose your solution. added a content webpart with my js control. Here is an interesting link: blog.riccardocelesti.it/… Commented Aug 17, 2015 at 16:38
  • It should be PreSaveItem() since the save button is defined as following: onclick="if (!PreSaveItem()) return false;//else)"
    – Emaborsa
    Commented Dec 10, 2018 at 14:45
0

There is no possibility to return to the form from an Eventhandler. I had the same issue like you trying to validate something on editform. It is not so easy when you are trying to make asynchronous calls like you would need to do.

Maybe take a look at Jslink and formvalidation: https://www.martinhatch.com/2013/08/jslink-and-display-templates-part-1-overview-url-tokens-and-applying-jslink-to-objects.html

You can then insert a reference to your js-File into the Edit-Form or NewForm Webpart at Miscellaneous in the JSLink Property.

Otherwise you could use the PreSave() action in your javascript which will be executed when the user clicks on save. This also gives you the possibility to keep the entered data and display message if not valid: http://www.c-sharpcorner.com/Blogs/47653/presaveaction-in-sharepoint-2010.aspx

Your Answer

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

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