SP Online, task list. Created calculated field with this formula:
=IF([Task Status]="Completed","<DIV><img src='https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png /></DIV>","")
it works but does not show icon (shows text):
Returned value is 'Number', so as I uunderstang SharePoint should render html and show image.. How can I fix it?
Update:
Thank You much guys for Your answers! Replaced with CSR (attached like "~sitecollection/libname/filename.js" in Webpart -> Miscellaneous -> JsLink section):
(function () {
// custom JSlink overrides hierarchytaskslist.js, so we need to load it by ourself
// https://sharepoint.stackexchange.com/questions/211494/csr-to-render-task-status-destroys-task-checkboxes
RegisterSod('hierarchytaskslist.js', '/_layouts/15/hierarchytaskslist.js');
LoadSodByKey('hierarchytaskslist.js', null);
var overrideCurrentContext = {};
overrideCurrentContext.Templates = {};
overrideCurrentContext.Templates.Fields = {
'Ico':
{
'View': returnIcon
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);
})();
function returnIcon(ctx) {
var isCurrentItemCompleted = ctx.CurrentItem["Checkmark"];
console.log("Is current item completed: " + isCurrentItemCompleted);
if (isCurrentItemCompleted === "Yes") {
var pathToIcon = "<span><img src='" + "https://server.sharepoint.com" + "/Style%20Library/project/ok-24.png' width='24px' height='24px'style='border:0px;'></span>";
return pathToIcon;
} else {
return "";
}
}
The only problem that remains - is that all works like a charm on Views pages, but not on Home.aspx, where I have other webparts with custom javascript.. Select/Deselect tasks does not wotk there at all, maybe something breaks hierarchytaskslist.js