Related Items prefilled when parent and child form opend as popup

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

08 Jun 2018

Hi,

i've tried to use the related items control on my form and prefill a lookup in the "child" form when creating new related items.
i followed the instructions on this site: https://spform.com/documentation/relate ... gular-mode

But the problem is:

the parent form opens in a dialog.
the child form opens in a dialog upon the parent dialog.
therefore the check

Code: Select all

 "if (window != window.top && window.top.fd) {"

wont work. The "window.top" is my list-view, not the new / edit form of parent list....
So the url parameter "ID" is not available, the namespace "fd" is not available (window.top.fd).....

how can i handle to give the tempparentid (in parent new form) or the real parent (in parent edit form) to the child form and prefill the lookup?

Why my lookup in the child list needs the additional column "ID" on the lookup field?

Thx alot!

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

08 Jun 2018

Dear Ragesoft,
Unfortunately, no way to do it, if the Parent Form is opened in dialog as well. Edit Form might still work for Quick Edit mode, but otherwise - not possible.
Cheers

ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

12 Jun 2018

So i have build a little workaround to always be sure to submit the correct parent-id to the child, independent from the popups opened

on each form, where the user have the option to create related items i put a button instead the "new element" link on the related items control and insert this javascript in the onclick to call the "new form" for the related item:

Code: Select all

// set a custom url parameter to deal with dialog "bug" and wrong parentId
// target-list checks if "isNaN" on parameter "Parent"
var parentId = fd.getUrlParam(window.location.href, 'ID');
var webUrl = _spPageContextInfo.webServerRelativeUrl;
var listNewForm = "/Lists/<ChildList>/fd_<ChildList>_New.aspx";
if(fd._formType() == "New" || parentId == ""){
	parentId = fd._tempParentId();
}
// open target form and set parent parameter
fd.openFormInDialog(webUrl + listNewForm,{"Parent":parentId});
and the child forms have this javascript:

Code: Select all

var parentId = window.GetUrlKeyValue('Parent');
if(parentId){
	if(isNaN(parentId)){
		// temp parent id
  		console.log("Opend from new");
    	$('#_fd_parent_temp > input').val(parentId);
	}else{
		// exisiting parent id
		console.log("Opend from edit");
	    fd.field('<parentLookup>').value(parseInt(parentId));
	}
	console.log("ParentID: " + parentId);
	$('.parentField').hide();
}
so the parent-lookup is only hidden in the new-form, but this is ok for us :)

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

12 Jun 2018

Dear ragesoft,
Great to hear that! This is an interesting workaround, we might even propose this solution if someone has the same question in the future. Thank you for posting it!
Cheers

ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

13 Jun 2018

1 problem with this solution:

If i create a new item, the correct "New-Form" is showing up to create the element.
But after saving, the content type is set the "Element". But element is not the default content type for this list!
So i have to remove "element" from the list completely to avoid it :)

How is the content type set, on the "normal" way? I never draged the "content type" field in the form before.

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

13 Jun 2018

Dear ragesoft,
Ah, yes, this is indeed likely to happen, as the ContentTypeId is a part of the URL. I recommend creating basic forms with ContentType field to check what the IDs are, then try to replicate the change of the ContentTypeId with JavaScript. This might help.
Cheers

ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

15 Jun 2018

One more problem:
If i call the child-form as popup, create a new child, save the child: the child-form close and reload the parent --> right now it reloads the window.top.
How to avoid reloading the parent form after creating a child? (i think the reload is requierd to show the new child directly in the new-form of the parent)

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

16 Jun 2018

Dear ragesoft,
This can only be avoided in Quick Edit mode, otherwise it has to reload.
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests