Here is my foundation setup. create two list
1.项目联系人信息: Contains master data that provides lookup values to test3
2.test3 Contains values and one column to lookup values from [项目联系人信息]
<script type="text/javascript">
function getMaxID(lsttitle){
var mx = 0 ;$.each($('select[title="'+lsttitle+'"] option'),function(i,v){
mx=Math.max(mx, v.value)
})
return mx;
}
function openDialog(pageUrl,lsttitle) {
var options = {
url: pageUrl,
title: lsttitle,
allowMaximize: false,
showClose: true,
width: 700,
height: 600,
dialogReturnValueCallback: function(result,returnValue){
if (result == SP.UI.DialogResult.OK) {
refreshcontact(lsttitle);
newcontactid = getMaxID(lsttitle)
$('select[title="'+lsttitle+'"]').val(newcontactid)
//console.log(returnValue)
//https://sharepoint.stackexchange.com/questions/38405/sharepoint-modal-help-pass-value-back-to-parent-when-closing
}
if (result == SP.UI.DialogResult.cancel) {
//do nothing, modal was closed
}
}
};
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}
function newcontactonclick(){
url = "https://alphafp.sharepoint.com/teams/Marketing/Lists/List2/newContact.aspx"
openDialog(url, 'contactname')
}
refreshcontact = function(lsttitle){
// lstName = lsttitle=="项目中介信息"?'中介联络人':lsttitle
$().SPServices.SPFilterDropdown({
relationshipList: "项目联系人信息",
relationshipListColumn: "Title",
columnName: "contactname",
CAMLQuery: "",
completefunc: null,
debug: false
});
}
</script>
and here is the button the opens the dialog, when new record is saved from the dialog, it refreshes the combobox using "refreshcontact" function as above.
<div style="padding:5px;margin-left:5px !important;">
<a href="#" onclick='javascript:newcontactonclick()' style="float:left;display:inline;"
>新增聯絡人</a>
</div>
The testing step is:
- Create new item using new form.
- Add new lookup item using the dialog
- Then refresh the selection box with JS.
- save the list
And it ends up an error page, the funny thing is that I have another input but using multiple select, which works fine...