0

I have a small request from my manager.He wants a custom complete button which checks if the fields are empty and if not provides an error and if not then the item gets saved in the list. I know there is a save button already but he does not want the fields to be required through share point column property. I want to implement the above solution but there is a problem : i do not have the admin access of the site so the best i can do is to add a button through content editor and write the validations but i still do not know how to go about it.

If there is anything you guys can help me out with, it would be appreciated.

Thanks

1
  • if they are empty provides an error and if not the item gets saved in the list*. Please ignore the mistake. Apr 11, 2018 at 12:26

1 Answer 1

3

You can PreSaveAction() function to validate the field(s) before saving the item,

in the new item form, click edit page then add content editor web part and add your PreSaveAction(), it will execute when user clicks Save button & before the item is saved, below is a sample:

<script type="text/javascript">
function PreSaveAction() 
{

        if ($("input[title='field name']").val()=="")
            {
               alert('Please, fill the field etc ..."');
              return false;
            }

        else
              return true
}
 </script>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
7
  • Thank You saeed. But how do i create a new button for the java script action to take place.I wan to perform the presavefunction on a new custom button rather than a save button. Save button helps you to save the fields even when all the fields are not filled. So could you help me with the solution ? Apr 12, 2018 at 4:26
  • As i mentioned in my answer, this function will help you validate the fields before saving, above is sample, if you are using jquery like in the sample don't forget to add the jquery js reference to your function @jayantkhushalani
    – A.Saéed
    Apr 13, 2018 at 9:35
  • yes the above code works fine. i have few doubts, could you help me out? Apr 13, 2018 at 9:41
  • @jayantkhushalani sure , what's the issue?!
    – A.Saéed
    Apr 13, 2018 at 14:00
  • i am trying to validate the people picker and i am able to do that but how do i set focus on the people picker after i show the error message in the alert? Apr 14, 2018 at 6:12

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.