0

I'm trying to customize the content type selector from a jslink file.

I tried the standard approach, but it does not trigger :

(function () {

    var customContentType = function (ctx) {
        return "it's working"
    };

    var overrideCtx = {};
    overrideCtx.Templates = {};

    overrideCtx.Templates.Fields = {
        "ContentType": {
            "EditForm": customContentType
        }
    };           
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

Also tried on ContentTypeId, but no more success.

Is there any way to customize Content Type selector ?

PS: I know I can hide the native drop down under the carpet and manually trigger event with

var oobCTSelector = document.querySelector("[id$='ContentTypeChoice']");
oobCTSelector.style.display = "none";
...
oobCTSelector.onchange();

but I thinks it's a bit hackish.

[Edit] One clue that let me think it's not even possible is that if I inspect the context object I get :

ctx.FieldControlModes

>Attachments: 2
> Author: 1
> Champ_x0020_CT_x0020_01: 2
> Created: 1
> Editor: 1
> Modified: 1
> Title: 2

There's no mention to content type field

  • Did you try ContentTypeChoice, just because...why not? It might not work at all, anyway. If you look at the rendering templates (DefaultTemplates.aspx), most of the forms have a ChangeContentType template that is separate from the ListFieldIterator or CSRListFieldIterator template, so it's quite possible that the Content Type drop-down is rendered on the server and never goes through the CSR cycle. – Dylan Cristy Feb 11 at 19:34
  • Unsuprisingly, it does not work using ContentTypeChoice. Where do you find the defaulttemplates.aspx ? (or did you mean ascx ?) – Steve B Feb 12 at 9:09
  • Ah yes, my bad, it is ascx. Found in the 15 hive /TEMPLATE/CONTROLTEMPLATES, you'll need to have an on-prem installation to get to them. – Dylan Cristy Feb 12 at 14:40

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.