Delete Button with jslink to delete related item
-
- Posts: 5
- Joined: Wed Mar 06, 2019
Hello,
i got a little problem to delete items with jslink in an related items list.
Thats my jslink code:
The code works fine in the listview but not not in any form.
I get the following error:
on this line of code
Script error: object expected
Can u help me plz?
i got a little problem to delete items with jslink in an related items list.
Thats my jslink code:
Code: Select all
(function () {
function view(ctx, field) {
// Get the markup that is by default rendered for the "Edit" field.
var editButtonHtml = (new ComputedFieldRenderer(field.Name)).RenderField(
ctx, field, ctx.CurrentItem, ctx.ListSchema);
if (editButtonHtml.replace(/ /gi,'')) {
// If the edit button is displayed, it means that the user has edit permissions.
// Then display a delete button also.
var deleteButtonHtml =
"<a href='#' title='Delete'><img src='/_layouts/15/images/delitem.gif' " +
"onclick='javascript:window.deleteItem(\"" + ctx.ListTitle + "\",this);'/></a>";
return editButtonHtml + " " + deleteButtonHtml;
}
return editButtonHtml;
}
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
'Edit': {
'View': view
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
window.deleteItem = function (listName, element) {
if (DeleteItemConfirmation()) {
// Extract the id of the clicked list item.
var id = $(element).closest("tr[iid]").attr("iid").split(',')[1];
$.ajax({
url: window._spPageContextInfo.webServerRelativeUrl +
"/_api/web/lists/getbytitle('" + listName + "')/items(" + id + ")",
type: "POST",
headers: {
"ACCEPT":"application/json;odata=verbose",
"content-type":"application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH":"*",
"X-HTTP-Method":"DELETE"
},
success: function(data) {
$(element).closest("tr[iid]").remove();
},
error: function(error) {
console.log(JSON.stringify(error));
}
});
}
}
I get the following error:
on this line of code
Code: Select all
if (DeleteItemConfirmation()) {
// Extract the id of the clicked list item.
var id = $(element).closest("tr[iid]").attr("iid").split(',')[1];
Can u help me plz?
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Douglenator,
Unfortunately, JS Link is not supported on any custom forms, either ours or created with SharePoint designer.
Unfortunately, JS Link is not supported on any custom forms, either ours or created with SharePoint designer.
Cheers
-
- Posts: 5
- Joined: Wed Mar 06, 2019
Is there any other way to do this ?
The easiest workaround would be a delete checkbox to delete files...
but i think this is not a verygood way to do that
Do u have a better idea for me?
The easiest workaround would be a delete checkbox to delete files...
but i think this is not a verygood way to do that
Do u have a better idea for me?
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Douglenator,
What exactly do you need to achieve? Delete multiple files at once?
Normally, the users should be able to delete files one by one like this:
What exactly do you need to achieve? Delete multiple files at once?
Normally, the users should be able to delete files one by one like this:
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 6 guests