Right now, the button just pulls up the Enrollment form. Instead, I am trying to get a single click enrollment button. When a user clicks Add to Wishlist, it should display a progress indicator and create a record in the Enrollments list. Then display Enrolled. Please help code below
(function () {
if (typeof SPClientTemplates === 'undefined')
return;
var wishlistCtx = {};
wishlistCtx.Templates = {};
//associate the various templates with rendering functions for our field.
//when a list view is returned to the user, SharePoint will fire the function associate with 'View'.
//when a list item is in New, SharePoint will fire the function associated with NewForm, etc.
wishlistCtx.Templates.Fields = {
//Recipekpi is the Name of our field
'Add_x0020_to_x0020_Wishlist': {
'View': wishlistView,
'DisplayForm': wishlistDisplay,
'EditForm': wishlistNewEdit, //using the same function for New and Edit, but they could be different
'NewForm': wishlistNewEdit
}
};
//register the template to render our field
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(wishlistCtx);
function wishlistNewEdit(ctx){
return "Save Topic First";
}
function wishlistDisplay(ctx) {
var id = getParameterByName("ID");
var url = "../sapiensEnrollments/NewForm.aspx?TopicID=" + id;
return "<button><a href='" + url + "'>Enroll</a></button>";
}
//function called when our field is shown in a View
function wishlistView(ctx) {
var url = ctx.listUrlDir + "../../sapiensEnrollments/NewForm.aspx?TopicID=" + ctx.CurrentItem.ID;
return "<button><a href='" + url + "'>Enroll</a></button>";
}
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
})();