I have a Mandatory field in a list. I need to save the item and not create the item.
I need to implement the it using custom JavaScript and not use the save button on the new form.
Also need to check if the mandatory fields are set and stop the item from being saved and show the validation messages.
The following does save the item but does not check if the field is manadatory. It also redirects the page to the edit form as required.
$("input[id='DummyButton']").bind("click", function() {
var clientContext = new SP.ClientContext(_spPageContextInfo.siteAbsoluteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Test');
var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(itemCreateInfo);
var title = $("input[id^='Title']").val();
var Teststandard = $("div[id^='testStandard'] p").html();
oListItem.set_item('Title', title);
oListItem.set_item('Tenures', tenures);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
function onQuerySucceeded() {
console.log('Item created: ' + oListItem.get_id());
$(location).attr('href',_spPageContextInfo.siteAbsoluteUrl + '/Lists/test/EditForm.aspx?ID=' + oListItem.get_id() + '&newedit=1');
}
function onQueryFailed(sender, args) {
console.log('Request failed. ' + args.get_message() +'\n' + args.get_stackTrace());
}
});
Is there a way to use the default save javascript or use the PreSaveAction()
function?