I am still not able to find a way to resolve this. Here is thestripped down version of the code. I have removed all unwanted code. Let me know how to solve this...
Create a list Foo with a date column "Due Date".Make title column non mandatory. Add this script in newform and editform.
<script src="/Style Library/jquery-1.11.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
var context,oList,collListItem,id,filterValue,Url;
$(document).ready(function()
{
Url=window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl
//Hookup save and redirection in NewForm
if(window.location.pathname.toLowerCase().indexOf("newform")!=-1)
{
SaveAndRedirectToEditForm();
}
else if(window.location.pathname.toLowerCase().indexOf("editform")!=-1)
{
SaveAndRedirectToAllItems();
}
});
function SaveAndRedirectToAllItems()
{
var button = $("input[id$=SaveItem]");
button.removeAttr("onclick");
button.click(function() {
context= new SP.ClientContext.get_current();
oList = context.get_web().get_lists().getByTitle('Foo');
id=getParameterByName("ID");
if(id!="")
{
collListItem=oList.getItemById(id);
SetItems();
context.executeQueryAsync(onSaveQuerySucceeded,onQueryFailed);
}
});
}
function SaveAndRedirectToEditForm()
{
var button = $("input[id$=SaveItem]");
button.removeAttr("onclick");
button.click(function() {
context= new SP.ClientContext.get_current();
oList = context.get_web().get_lists().getByTitle('Foo');
var itemCreateInfo = new SP.ListItemCreationInformation();
collListItem = oList.addItem(itemCreateInfo);
SetItems();
context.load(collListItem);
context.executeQueryAsync(onSaveQuerySucceeded,onQueryFailed);
});
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function SetItems()
{
if($("input[Title^='Due Date']").val()!="")
collListItem.set_item('DueDate',$("input[Title^='Due Date']").val());
collListItem.update();
}
//Redirect usre to edit/display form
function onSaveQuerySucceeded() {
if(window.location.pathname.toLowerCase().indexOf("newform")!=-1)
window.location.href="/lists/Foo/EditForm.aspx?ID="+collListItem.get_id();
else if(window.location.pathname.toLowerCase().indexOf("editform")!=-1)
{
var path="/lists/Foo/AllItems.aspx?View=%7B7677A2EB%2D9227%2D43EC%2D8C66%2DF732052795E3%7D&SelectedID="+id;
window.location.href=path;
}
}
/* Displays error if request failed*/
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
-
Edited by
sanjuv
Friday, May 29, 2015 6:55 AM