Prevent page refresh after save action

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
florian33385
Posts: 2
Joined: Mon Sep 24, 2018

24 Sep 2018

Hi,

I hope you can help me with a little problem that I have preventing your forms designer from refreshing the page after I invoke the click event from your save button. What I want is that the form creates the new item in the list but closes the form instead of refreshing. I tried to add an submit function where I wanted to prevent your event handler from relading the page but that didn't worked as I expected.
My goal is to call a function after the save action so I can update some other list items depending on field values and the id from the list item created by that form.

User avatar
AlexZver
Posts: 232
Joined: Mon Aug 27, 2018

24 Sep 2018

Hello,

Closing form after saving is a default behavior of the form, so please be sure you don't have any errors in the browser console during the saving process. It would be very helpful if you provide a video of your actions.

There are a few ways to implement your task, as I see it:

1) Redirect to edit page and send data with JSOM from the edit form. You will have access to all the data, including ID in the URL, but will need to go to edit form first.

How to redirect to the Edit form: https://spform.com/buttons/open-edit-fo ... sharepoint
How to retrieve list items: https://www.c-sharpcorner.com/UploadFil ... avascript/

2) Use a workflow or flow instead. It's probably the easiest option.

florian33385
Posts: 2
Joined: Mon Sep 24, 2018

28 Sep 2018

Hi again,

thanks for responding but I solved it in a different way.

I used "csr" via js-link and overwrote the "RenderHeroAddNewLink" function from "clientemplates.js" like so:

Code: Select all

function xRenderHeroAddNewLink(heroParam, renderCtx) {
  var clickEvent = '';
  $.ajax({
    url: _spPageContextInfo.webServerRelativeUrl + '/_api/web/lists/GetByTitle(\'' + renderCtx.ListTitle + '\')/Forms?$select=ServerRelativeUrl&$filter=FormType eq 8',
    method: 'GET',
    async: false,
    headers: {
      "Accept": "application/json; odata=verbose"
    },
    success: function (data) {
      clickEvent = 'createDlgFromURL(\'' + data.d.results[data.d.results.length - 1].ServerRelativeUrl + '?IsDlg=1\', JournalCreateCallbacks, true); return false;';
    }
  });
  var ret = [];

  ret.push('<a id="');
  ret.push(heroParam.heroId);
  ret.push('" class="ms-heroCommandLink"');
  ret.push(' href="');
  ret.push('javascript:;');
  //ret.push(heroParam.addNewUrl);
  ret.push('"');
  if (!heroParam.WOPIEnabled) {
    ret.push(' data-viewCtr="');
    ret.push(renderCtx.ctxId);
    ret.push('\" onclick=\"' + clickEvent + '"'); // Angepasstes Klick-Event
    // ret.push("\" onclick=\"NewItem2(event, &quot;");
    // ret.push(heroParam.addNewUrl);
    // ret.push("&quot;); return false;\" target=\"_self\"");
  }
  ret.push(" title=\"");
  ret.push(Strings.STS.L_SPAddNewItemTitle);
  ret.push("\">");
  if (heroParam.largeSize) {
    ret.push("<span class=\"ms-list-addnew-imgSpan20\">");
  } else {
    ret.push("<span class=\"ms-list-addnew-imgSpan16\">");
  }
  ret.push('<img id="');
  ret.push(heroParam.heroId + '-img');
  ret.push('" src="');
  ret.push(GetThemedImageUrl("spcommon.png"));
  if (heroParam.largeSize) {
    ret.push('" class="ms-list-addnew-img20"/>');
  } else {
    ret.push('" class="ms-list-addnew-img16"/>');
  }
  ret.push("</span><span>");
  ret.push(heroParam.addNewText);
  ret.push("</span></a>");
  if (heroParam.WOPIEnabled) {
    AddPostRenderCallback(renderCtx, CreateNewDocumentCallout);
  }
  return ret.join('');
}
The reason why I do not use workflows is that I'm not sure if they will still work when I'm migrating to SP2019.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests