Add a new Save button on the newform page in the sharepoint2013 list

Source: Internet
Author: User

Yesterday, a colleague asked me how to add a save and new button on the newform. ASPX page of sharepoint2013. The SAVE and new functions are implemented. The SAVE Function and the default Save button have the same effect.

Effect

The idea here is as follows:

1) Use juqery to dynamically Add a saveandnew button

2) The Click Event of the new button will call the click method of the default Save button

3) after the Click Event of the new button, the page Jump mainly depends on the Source Parameter of the URL. Therefore, we must rewrite the method for obtaining this parameter. The read of this parameter is in init. debug. JS's geturlkeyvalue method.

The modification method is as follows:

Window. savefun = geturlkeyvalue;
Window. geturlkeyvalue = function (keyname, bnodecode, URL, bcaseinsensitive ){
If (keyname! = "Source "){
Return window. savefun (keyname, bnodecode, URL, bcaseinsensitive );
}
Else {
Return "/lists/custlist/newform. aspx ";
}
}

First, I need to save the original geturlkeyvalue method and overwrite the default geturlkeyvalue method. This is the function call status.

Because the overwrite of the geturlkeyvalue function is in the "Save New" button event, when I enter the page, I directly click "save" to jump to the allitems page. aspx, click "Save New" to jump to newform. on the ASPX page, if an error occurs on the customer service side when you click "Save New", when we modify the data and click "save, there is a problem at this time (the page jumps to newform. ASPX page instead of allitems. aspx). I have been searching for a long time and haven't found a place for real client verification. (If you know anything, please advise. It's not the code below if (! Presaveitem () return false; If (spclientforms. clientformmanager. submitclientform ('wpq2 ') return false). Finally, the rogue has to use the setinterval method to check whether the page has error information. If yes, we will restore the geturlkeyvalue method.

The final code is as follows:

 <script type="text/javascript" src="/siteassets/js/jquery.js"></script>    <script type="text/javascript">        $(document).ready(function () {            var btnsave = $("input[id*='diidIOSaveItem']")[1];            var tableSave = $(btnsave).parents(".ms-toolbar").eq(0);            var strsaveAndNew = ' <td class="ms-toolbar" nowrap="nowrap"><input type="button" value="SaveAndNew" id="btnsaveAndNew" /></td><td class="ms-separator"> </td>';            $(strsaveAndNew).insertBefore(tableSave);            window.savefun = GetUrlKeyValue;            $("#btnsaveAndNew").click(function () {                window.btnsaveAndNew = true;                window.GetUrlKeyValue = function (keyName, bNoDecode, url, bCaseInsensitive) {                    if (keyName != "Source") {                        return window.savefun(keyName, bNoDecode, url, bCaseInsensitive);                    }                    else {                        return "/Lists/CustList/NewForm.aspx";                    }                }                $(btnsave).click();                window.btnsaveAndNew = false;            });        });        setInterval(function () {            var errors = $("span[id^='Error_']");            if (errors.length > 0 && !window.btnsaveAndNew) {                window.GetUrlKeyValue = window.savefun;            }        }, 100);    </script>


If something is wrong, please make a brick.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.