$('.ms-formtable nobr:contains("Field Display Name")').closest('tr').hide();
And this article shows how to apply that same jQuery technique using client side rendering / template overrides. But I wondered, is there a way to hide fields on forms using just what you have available during CSR code execution? Is there a way to do it without needing jQuery?
Indeed there is:
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
"Field1": {
"NewForm": hideField,
"EditForm": hideField
},
"Field2": {
"NewForm": hideField,
"EditForm": hideField
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
// the hideField function uses ctx.CurrentFieldSchema.Name,
// so it is generic enough to be used for multiple fields
function hideField(ctx) {
// get the span that represents the field's actual edit control
var span = $get(ctx.FormUniqueId + ctx.FormContext.listAttributes.Id + ctx.CurrentFieldSchema.Name);
// still need to go up two levels to hide the entire <tr>
span.parentNode.parentNode.setAttribute("style", "display:none");
return "";
}
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
"Field1": {
"NewForm": hideField,
"EditForm": hideField
},
"Field2": {
"NewForm": hideField,
"EditForm": hideField
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
// the hideField function uses ctx.CurrentFieldSchema.Name,
// so it is generic enough to be used for multiple fields
function hideField(ctx) {
// get the span that represents the field's actual edit control
var span = $get(ctx.FormUniqueId + ctx.FormContext.listAttributes.Id + ctx.CurrentFieldSchema.Name);
// still need to go up two levels to hide the entire <tr>
span.parentNode.parentNode.setAttribute("style", "display:none");
return "";
}
I guess it just goes to show you how much you can actually do with CSR.