我正在尝试使用一些JavaScript来打开SharePoint模式对话框以提示用户输入,然后将该值存储到变量中。 有谁知道如何做到这一点? 我正在为Nintex任务表单执行此操作。
I am trying to use some JavaScript to open up a SharePoint Modal Dialog to prompt the user for input and then store that value into a variable. Does anyone know how to do this? I am doing this for a Nintex task form.
最满意答案
你试过什么了? 最简单的选择是利用SP.UI.ModalDialog类,该类提供打开本机SP模式的方法 - 您可以通过URL参数加载单独的页面(ASPX,HTML等)或直接将HTML传递给模式渲染。
无论采用哪种方法,您的标记都可以包含<input>以捕获用户的值,并随附JS以将输入值存储在任何您想要的位置(包括在变量中)。
根据您正在使用的其他JS(如果有)或如何设置页面,您可能还需要利用SP2013的“脚本按需”(SOD)功能来确保加载SP模态所需的JS。
这是一个简单的例子:
function OpenMyModal(SomeVar) { // If using inline HTML, first create a parent element... var MyHtmlElement = document.createElement('div'); // ... then populate it MyHtmlElement.innerHTML = '<input... />'; // Define the Modal's options var options = { // define a URL (and yes, you can pass params to that URL) or reference your HTML object, but NOT both! url: '../MyPage.aspx?MyParam=' + SomeVar + '&IsDlg=1', // html: MyHtmlElement, tite: 'Modal Title', allowMaximize: false, showClose: true, width: 430, height: 230 }; // This ensures the supporting JS needed is loaded on the page SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options); return false; }What have you tried so far? The simplest option would be to leverage the SP.UI.ModalDialog class which provides methods for opening a native SP modal - you can load either a separate page (ASPX, HTML, etc) via URL parameter or pass HTML directly to the modal to be rendered.
With either approach, your markup could then include an <input> to capture the value from the user and accompanying JS to store the input value wherever you want (including in a variable).
Depending on what other JS you're using (if any) or how the page is setup, you may also need to leverage SP2013's "Script On Demand" (SOD) function to ensure the necessary JS for the SP Modal is loaded.
Here's a simple example:
function OpenMyModal(SomeVar) { // If using inline HTML, first create a parent element... var MyHtmlElement = document.createElement('div'); // ... then populate it MyHtmlElement.innerHTML = '<input... />'; // Define the Modal's options var options = { // define a URL (and yes, you can pass params to that URL) or reference your HTML object, but NOT both! url: '../MyPage.aspx?MyParam=' + SomeVar + '&IsDlg=1', // html: MyHtmlElement, tite: 'Modal Title', allowMaximize: false, showClose: true, width: 430, height: 230 }; // This ensures the supporting JS needed is loaded on the page SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options); return false; }更多推荐
发布评论