Page 1 of 2
Redirect to display view
Posted: 26 Sep 2017
by james.martin
Hi,
I'm assuming this is probably super simple, but I've searched the forum and tried several things and I can't figure it out.
How would I redirect back to the display form after clicking save or cancel on the edit form? I tried using this as the redirect URL but it always sends me to the same display form and not the one I was on:
/xxx/Lists/xxx/fd_Item_DisplayForm.aspx?{ItemId}
Thanks,
Jim
Re: Redirect to display view
Posted: 26 Sep 2017
by Nikita Kurguzov
Hello, James!
Check out this article -
https://spform.com/buttons/open-edit-fo ... sharepoint
You'll just need to replace in your code Edit Form for Display Form and you are good. Something like this should do:
Code: Select all
fd.onsubmit(function() {
var uri = fd.setUrlParam(decodeURIComponent(window.location.href), 'FDRedirectWithID', 'fd_Item_DisplayForm.aspx?ID=');
fd.sourceFormParam(uri);
return true;
});
Place it into the JavaScript editor, not on the Save button,
Re: Redirect to display view
Posted: 26 Sep 2017
by james.martin
Thanks Nikita,
Unfortunately inserting the above into the JavaScript editor just redirects me to the edit page

Re: Redirect to display view
Posted: 27 Sep 2017
by Nikita Kurguzov
Hello, James!
That's strange, I've just tested the code and it worked for me. Can you tell me the version of SharePoint and Forms Designer you are using?
Re: Redirect to display view
Posted: 27 Sep 2017
by james.martin
Hi Nikita,
We are on SharePoint Online (Office 365), forms designer client 3.1.4
Thanks,
Jim
Re: Redirect to display view
Posted: 27 Sep 2017
by Nikita Kurguzov
Okay, same for me. What about the Form itself? Do you open it normally or perhaps it's opened in dialog mode, as a pop-up window? Can you provide some screenshots of how you open the form and how it redirects you to the Edit page? Maybe I'll see something that causes it.
Re: Redirect to display view
Posted: 27 Sep 2017
by james.martin
Nope, it opens in full screen (not dialog).
Here is where I inserted the code:

- 2017-09-27_10-27-11.png (177.06 KiB) Viewed 1881 times
Here is the edit screen before I click save:

- iexplore_2017-09-27_10-28-31.png (83.33 KiB) Viewed 1881 times
Here is where it redirects. Same form, in edit mode. It does refresh the screen so I know it is doing something:

- iexplore_2017-09-27_10-29-07.png (112.44 KiB) Viewed 1881 times
Re: Redirect to display view
Posted: 28 Sep 2017
by Nikita Kurguzov
Okay, it might sound obvious, but it seems that you have several tabs. Is there any chance that there are mandatory fields in other tabs that are left empty? In this case, the page will reload, but will not submit and won't redirect you to display form.
You can try adding this code to your Form, it will redirect you to the tab with the error, if there are any:
Code: Select all
function checkTabsForErrors(){
if($('span[role="alert"]').text()){
var error = $('span[role="alert"]').first();
openTabs(error);
}
}
checkTabsForErrors();
function openTabs(element){
var correctTab = element.parents('.ui-tabs-panel')[0];
var tabId = correctTab.id;
var IdAndTab = tabId.split('-tab-');
var ID = IdAndTab[0].split('-')[1];
$('#' + IdAndTab[0]).tabs('option', 'active', IdAndTab[1] - 1);
if (ID > 0){
openTabs($('#' + IdAndTab[0]));
}
}
Re: Redirect to display view
Posted: 28 Sep 2017
by james.martin
Thanks. Still no luck. I added the code and it didn't show any errors on other tabs. As an extra precaution, I changed it so that no fields were mandatory. I also tried the redirect code on another form and I get the same result.
Re: Redirect to display view
Posted: 28 Sep 2017
by Nikita Kurguzov
And if you remove the code? Will you be able to save the item normally without redirection?