SP2010使用模态对话框表格:初学者问题
-
09-12-2019 - |
题
所以我试图弄清楚如何使用一些Java脚本来使用模态对话框来显示新项目表单。下面是我到目前为止的目标,但它不起作用,我不确定什么是错误,丢失等的部分。
//use a button for example
<input type="button" value="Launch Dialog" id="myDialog" onclick="openDiaForm();"/>
//inside script tags under PlaceHolder Main
function openDiaForm()
{
var diaOptions = SP.UI.create_DialogOptions();
diaOptions.url = 'http://mySPDev/sites/jQueryPractice/Lists/ExampleList/NewForm.aspx?ID=' + 1 + '&IsDlg=1';
diaOptions.url += "?Source=" + document.url;
diaOptions.width = 400;
diaOptions.height = 300;
diaOptions.title = "My Custom Dialog Form";
diaOptions.dialogReturnValueCallback = function.createDelegate(null, CloseCallBack);
SP.UI.ModalDialog.showModalDialog(diaOptions);
}
function CloseCallBack(result, returnValue)
{
if (result == SP.UI.DialogResult.OK)
{
alert('clicked ok because I do not know how to work with result yet!');
}
else
{
alert('click cancel because I still do not know how to work with result!');
}
}
.
所以基本上,我只是在寻找学习如何在模态对话框中为列表中打开新的项目表单。我尚未达到结果,以便这样做,但是现在我似乎无法让对话。再次,我找到了一个例子,我正在努力学习我所拥有的,但需要一些帮助;任何帮助都非常感谢!
编辑:忘了提到我确实有页面中的脚本引用了sp.js
;有其他JavaScript / jQuery操作工作正常。
解决方案
以下代码正在工作。我在代码中发表了2个错误。
//use a button for example
<input type="button" value="Launch Dialog" id="myDialog" onclick="openDiaForm();"/>
//inside script tags under PlaceHolder Main
function openDiaForm()
{
//Use SP.UI.$create_DialogOptions() instead of SP.UI.create_DialogOptions()
//The name of the method starts with a "$"
var diaOptions = SP.UI.$create_DialogOptions();
diaOptions.url = 'http://mySPDev/sites/jQueryPractice/Lists/ExampleList/NewForm.aspx?ID=' + 1 + '&IsDlg=1';
diaOptions.url += "?Source=" + document.url;
diaOptions.width = 400;
diaOptions.height = 300;
diaOptions.title = "My Custom Dialog Form";
//Use Function.createDelegate(null, CloseCallBack) instead of function.createDelegate(null, CloseCallBack);
//The createDelegate method is part of the Function object. "function" is used to define a new function.
diaOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseCallBack);
SP.UI.ModalDialog.showModalDialog(diaOptions);
}
function CloseCallBack(result, returnValue)
{
if (result == SP.UI.DialogResult.OK)
{
alert('clicked ok because I do not know how to work with result yet!');
}
else
{
alert('click cancel because I still do not know how to work with result!');
}
}
. 其他提示
此脚本应该打开一个弹出窗口,但您需要更新URL和列表ID以适应您的环境。
.
<script type="text/javascript">
function silentCallback(dialogResult, returnValue) {
}
function refreshCallback(dialogResult, returnValue) {
SP.UI.Notify.addNotification('Operation Successful!');
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
var orderPrinterOptions= {
url: "/xxx/PrinterList/_layouts/listform.aspx?PageType=8&ListId={5BF16642-B7C4-4E54- 990D-E0E040F97DA9}&RootFolder=",
title: "Order a Printer",
allowMaximize: true,
showClose: true,
width: 650,
height: 525,
dialogReturnValueCallback: silentCallback};
function orderPrinter()
{SP.UI.ModalDialog.showModalDialog(orderPrinterOptions);}
</script>
<a href="javascript:orderPrinter()"><img width="234" height="232" alt="orderprinter.png" src="/xxx/PrinterList/Shared%20Documents/orderprinter.png" border="0" style="margin: 5px; width: 219px; height: 219px"/></a>
<div class="ms-rteFontSize-3" style="text-align: center">Order New Printer </div>
您可以将所有此代码直接纳入内容编辑器webpart。我希望这有帮助!