Redirect to display view

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
james.martin
Posts: 10
Joined: Mon Sep 25, 2017

26 Sep 2017

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

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

26 Sep 2017

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,
Cheers

james.martin
Posts: 10
Joined: Mon Sep 25, 2017

26 Sep 2017

Thanks Nikita,
Unfortunately inserting the above into the JavaScript editor just redirects me to the edit page :-(

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

27 Sep 2017

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?
Cheers

james.martin
Posts: 10
Joined: Mon Sep 25, 2017

27 Sep 2017

Hi Nikita,

We are on SharePoint Online (Office 365), forms designer client 3.1.4

Thanks,
Jim

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

27 Sep 2017

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.
Cheers

james.martin
Posts: 10
Joined: Mon Sep 25, 2017

27 Sep 2017

Nope, it opens in full screen (not dialog).

Here is where I inserted the code:
2017-09-27_10-27-11.png
2017-09-27_10-27-11.png (177.06 KiB) Viewed 1254 times
Here is the edit screen before I click save:
iexplore_2017-09-27_10-28-31.png
iexplore_2017-09-27_10-28-31.png (83.33 KiB) Viewed 1254 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
iexplore_2017-09-27_10-29-07.png (112.44 KiB) Viewed 1254 times

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

28 Sep 2017

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]));
	}
}
Cheers

james.martin
Posts: 10
Joined: Mon Sep 25, 2017

28 Sep 2017

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.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

28 Sep 2017

And if you remove the code? Will you be able to save the item normally without redirection?
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests