EDIT
as iv noted here, you need to understand that there is two things going on here.
1) you have the parent list that your opening up that you edit but havent saved and then you open up a child within the parent form that you also open up and want to creat.
2) saving the child sends a postback from the parent form to save the child details. This loses focus on your parent element.
the child element in JS ModalDialog is essentially an iframe within the parent.
so you have two options.
1) do as i said above by calling as you have but instead have some logic in code to call the return function back to the parent to save.
2) save the parent first using partial postback and then open and save the child
EDIT
Ok i have one solution for you.
It means you have to add the new item on the item edit tho before you edit the item it loads the new popup form! i will keep on looking into the main solution. so far i can get the page to load the parent and when you click save it loads the child that you can save but you need to click on save again to clear and save the edited parent!
ExecuteOrDelayUntilScriptLoaded(PreSaveAction,"sp.js");
function callthismethod()
{
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url ='http://sharesite/sites/mysite1/Lists/Time3/NewForm.aspx';
dialogOptions.width = 750;
dialogOptions.height = 500;
dialogOptions.dialogReturnValueCallback = Function.createDelegate( null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(dialogOptions);
}
EDIT
You ow me big time ;) , everyone online said its not possible due to multiple partial postbacks going on... but its not ;).
to explain. you have the parent and the parent gets changed... you then click save and that opens the child and you save. It causes a postback but you already have a save item event that is already called causing JS to get confused!
solution....
do the same as above. this time before we call the save item, when we load the parent edit form we want to get the button save event name for later use. we then call the dialog for the child and on save (ok) on the child we can then call the save item event for the parent. the child is saved and closed. On the parent iv put an if statment to tell that we have already done the child so no need to call it but we can go a do a postback using the save button instead! so this is where the button event name comes in handy to call the postback event to save the parent list :)
<script type="text/javascript">
var setTrue = false;
var target;
var contName;
function PreSaveItem()
{
//on first load global varible setTrue is false so we can load the popup.
//but when true it will save parent list imitating save click event.
if ("function"==typeof(PreSaveAction)&& setTrue == false)
{
//get the clicked save button so that we can use the id (name) later to save when doing a postback.
target = event.target || event.srcElement;
contName = target.name;
//call the save action to load the child list
PreSaveAction();
}
else
{
//do postback with parent save button manually
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(contName, "", true, "", "", false, true));
}
}
//function that creates child popup to add new item to a child list
function PreSaveAction()
{
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = 'http://sharesite/sites/mysite1/Lists/Time3/NewForm.aspx'';
dialogOptions.width = 750;
dialogOptions.height = 500;
dialogOptions.dialogReturnValueCallback = Function.createDelegate( null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(dialogOptions);
}
//actions (save/cancel) for the child form
function CloseCallback(strReturnValue, target)
{
if (strReturnValue === SP.UI.DialogResult.OK)
{
//if we save than set global bool to true
setTrue = true;
alert("Thank you for adding time value");
//call presave item for parent list save
PreSaveItem();
}
if (strReturnValue === SP.UI.DialogResult.cancel)
{
setTrue = false;
alert( "You clicked cancel!");
}
}
</script>
PreSaveItem()
function, you're calling theOpenDialog()
function withreturn OpenDialog(url)
.OpenDialog()
returns false, so wouldn't that cause thePreSaveItem()
function to stop the first list item from saving?return false;
inOpenDialog()
did nothing).