gpt4 book ai didi

javascript - 允许保存新项目并在 SharePoint NewForm.aspx 中继续

转载 作者:行者123 更新时间:2023-11-30 12:25:52 25 4
gpt4 key购买 nike

简述:如何使默认的 SharePoint NewForm.aspx 添加一个项目并停留在输入页面而不是返回到 ListView AllItems?
长:
我被要求允许 SharePoint 用户在 SharePoint 列表中输入许多新项目,而不必在每次保存时返回到 AllItems。
此要求适用于许多列表,因此我不想为每种可能的内容类型开发特定代码。
我虽然可以编写一个简短的 js 文件并在用户想要保存并继续时使用它。
到目前为止,我尝试在内容编辑器 Web 部件 (CEWP) 中添加“保存并继续”行为。
我的第一种方法是更改​​ Source= 参数但没有成功(取消也返回到新源或在 preSaveAction() 中设置时忽略源。
然后我尝试在 preSaveAction 中设置表单操作:

<script type="text/javascript">
JSRequest.EnsureSetup();
var src = JSRequest.QueryString["Source"];
var exit = JSRequest.QueryString["exit"];
var isDialog = JSRequest.QueryString["IsDlg"];
var dlgParam = "";
if (isDialog)
dlgParam = "&IsDlg="+isDialog;
//If exit is defined its keeping default source parameter
if (exit) {
document.forms.aspnetForm.action= location.pathname+"?Source="+exit+dlgParam;
}
function PreSaveAction(){
//before saving the original source is saved in exit
exit=JSRequest.QueryString["Source"];
src=escapeProperly(window.location.protocol + '//' + window.location.host + _spPageContextInfo.serverRequestPath);
document.forms.aspnetForm.action=location.pathname+"?Source="+src+"&exit="+exit+dlgParam;
return true;

操作按预期更新,但在保存新项目时用户仍被重定向到 AllItems.aspx。

另一种尝试是添加一个特定的按钮,重复使用功能区和页面按钮中使用的 SharePoint javascript 操作

<script type="text/javascript">
function adressePage() {
return window.location.protocol + '//' + window.location.host + _spPageContextInfo.serverRequestPath;
}

function saveContinue() {
document.getElementById("cmdSaveContinue").disabled=true;

if (!PreSaveItem()) return false;
if (SPClientForms.ClientFormManager.SubmitClientForm("WPQ2")) {
SP.UI.Notify.addNotification("Saving ...", false);
window.location = adressePage();
} else {
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("cmdSaveContinue", "", true, "", adressePage(), false, true));
}
document.getElementById("cmdSaveContinue").disabled=false;
}
</script>
<input id="cmdSaveContinue" onclick="javascript:return saveContinue();" type="button" value="Enregistrer et continuer" style="top: -5.5em; position: relative;"/>

这样,处理表单验证并保存项目。
如果返回错误消息,表单将保留在 NewItem 上,但在执行 window.location=... 后错误消息将丢失。
当一切正常时,项目被保存并且用户在一个新的空 NewForm.aspx 上。
但是 SharePoint SPClientForms.ClientFormManager.SubmitClientForm("WPQ2") 是异步执行的,有时(不总是)重定向到AllItems 在我的重定向结束后出现。

我被困在这一点上,害怕在添加列表时被迫编辑 SPDesigner 中的每个 NewForm 页面...
信息:本地 SharePoint Server 2013,SPDesigner 可能

最佳答案

您可以通过 InfoPath 执行此操作,如果您拥有 SP on prem 和 SPDesigner 访问权限,则应该可以使用它。如果转到 InfoPath 并自定义表单,则可以转到“数据”>“提交选项”>(高级 >>)>“提交后”>“新建表单”。

您可以在谷歌上搜索“InfoPath Save and New”或转到 Microsoft 站点并查看 this演练。他们的演练建议使用两个按钮,其中一个打开新表单,另一个关闭表单。

关于javascript - 允许保存新项目并在 SharePoint NewForm.aspx 中继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29417632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com