none
PreSave with page reload RRS feed

  • Question

  • Hi All,

    I have a presave function, once the item is saved I need to reload the page.

    function PreSaveAction() {
        
        var txtTitle = $(":input[title='Title']").val();
        
        if (txtTitle == "") {
            alert("Please enter a title");
            return false;
        } else {
            return true;
            RefreshPage(SP.UI.DialogResult.OK);
        }
    
    
    }


    Thanks in Advance, Jiniv Thakkar

    Tuesday, November 26, 2019 1:56 PM

Answers

  • Hi Jiniv,

    To solve this issue, we don't need refresh the page, we can override the default calendar  function to achieve it.

    You can add the code to change color of buttons in the "changeBtnColor" function in below code.

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
    function changeBtnColor(){
    	//add code to change color of buttons
    	alert("test");
    }
    ExecuteOrDelayUntilScriptLoaded(CustomizeCalendarEvents, "SP.UI.ApplicationPages.Calendar.js");
    function CustomizeCalendarEvents() {
    	//Month Calendar View
    	SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids_Old = SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids;
    	SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids = function SP_UI_ApplicationPages_SummaryCalendarView$renderGrids($p0) {
    		this.renderGrids_Old($p0);
    		changeBtnColor();
    	};
    }
    </script>

    More information:

    Enhancing SharePoint 2013 Calendar sp.ui.applicationpages.calendar.js JavaScript Functionality

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    Thursday, November 28, 2019 8:02 AM
    Moderator

All replies

  • check the following forum thread: Automatically refresh the AllItems.aspx page after the Display View modal dialog is closed. In your case instead of DispForm.aspx you will need to work with NewForm.aspx/EditForm.aspx.

    Blog - http://sadomovalex.blogspot.com
    Dynamic CAML queries via C# - https://github.com/sadomovalex/camlex

    Tuesday, November 26, 2019 3:42 PM
  • Hi Jiniv,

    We can change the "Source=" of url to achieve the reload page, example, add the code below into script editor web part in newform.aspx page.

    <script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
    	var stringURL = location.href;
    	if(stringURL.indexOf("AllItems")>-1){
    		stringURL = stringURL.replace(stringURL.substring(stringURL.indexOf("Source="),stringURL.length),'Source='+stringURL.split('?')[0]);
    		location.href = stringURL;
    	}
    	if(stringURL.indexOf("Source=")==-1){
    		location.href = location.href+"?Source="+location.href;
    	}
    })
    function PreSaveAction() { 	
        var txtTitle = $(":input[title='Title']").val(); 
        if (txtTitle == "") {
            alert("Please enter a title");
            return false;
        } else {
            return true;      
        }
    }
    </script> 

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, November 27, 2019 2:25 AM
    Moderator
  • Hi, 

    My usecase, I have a page on which I have calendar added, when user tries to add event, the new form opens as pop up, when the event is added we are setting data in cache for the event type which will change the color of buttons on the page.

    The problem is that we have to refresh the page, so see the change in color, so if we can reload the page after every event added, the color of buttons would change automatically without manual refresh.



    Thanks in Advance, Jiniv Thakkar


    Wednesday, November 27, 2019 11:42 AM
  • Hi Jiniv,

    To solve this issue, we don't need refresh the page, we can override the default calendar  function to achieve it.

    You can add the code to change color of buttons in the "changeBtnColor" function in below code.

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
    function changeBtnColor(){
    	//add code to change color of buttons
    	alert("test");
    }
    ExecuteOrDelayUntilScriptLoaded(CustomizeCalendarEvents, "SP.UI.ApplicationPages.Calendar.js");
    function CustomizeCalendarEvents() {
    	//Month Calendar View
    	SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids_Old = SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids;
    	SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids = function SP_UI_ApplicationPages_SummaryCalendarView$renderGrids($p0) {
    		this.renderGrids_Old($p0);
    		changeBtnColor();
    	};
    }
    </script>

    More information:

    Enhancing SharePoint 2013 Calendar sp.ui.applicationpages.calendar.js JavaScript Functionality

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    Thursday, November 28, 2019 8:02 AM
    Moderator