短:如何使一個默認的SharePoint NewForm.aspx添加一個項目並留在輸入頁面而不是返回到列表視圖AllItems?
長:
我被要求允許SharePoint用戶輸入許多新項目到SharePoint列表,而不必在每次保存時都返回AllItems。
此要求適用於許多列表,因此我不想爲每種可能的內容類型開發特定的代碼。
我雖然可以編寫一個簡短的js文件,並在用戶想要保存並繼續時使用它。
到目前爲止,我試圖在內容編輯器Web部件(CEWP)中添加「保存並繼續」行爲。
我的第一種方法是改變源=參數,但沒有成功(無論是取消返回也到新源或preSaveAction設置時被忽略的來源()。
然後我試圖設置preSaveAction表單動作:如預期允許保存新項目,並繼續在SharePoint NewForm.aspx
<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
的另一種嘗試是增加特定的按鈕重用的JavaScript中使用動作的SharePoint功能區和頁面按鈕
<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服務器2013,SPDesigner可能
不得不編輯每個帶有停產產品的NewForm都會涉及很多工作。我將失去更少的時間解釋用戶,這是不可能的。儘管感謝您的建議。 – Gholmyrr 2015-04-07 08:12:14