Hide specific Content Type from form dropdown

I have a list with multiple content types. It's been decided we don't need one of them anymore so I've set it to not to be visible on new button (as we don't want to delete it to preserve historical content). This does remove it from the new button on the list but the Content Type field on the form(s) still has it listed. How do I hide the specific content type from the content type selector on the form so users can't pick it?

I can remove options from a regular drop down, but it returns a null error reading dataSource if I try it with the ContentType field.
fd.field("ContentType").widget.dataSource.data().remove("Other");
(tried both with the content type name as well as id)

I've also tried $(fd.field('ContentType').$el).find('option') to go through the options and maybe remove it from there but it doesn't find anything (length 0)

Any other methods I could try?

Dear @teddy0bear,
Please, try the following:
$(fd.field('ContentType').$el).find('option[value="0x0103006DF10AFB92B7754C85919864AB86D347"]').remove();

Value is Content Type ID:

No errors but doesn't work

Dear @teddy0bear,
Do you wrap it inside fd.spRendered()?

It should go like this on the form:

fd.spRendered(function(){
 $(fd.field('ContentType').$el).find('option[value="0x0103006DF10AFB92B7754C85919864AB86D347"]').remove();
});

Yes, it is wrapped in the fd.spRendered section. I tried with the content type I'm trying to remove as well as one of the still active ones and neither of them disappeared.

Hello @teddy0bear,

Please wrap the code inside the ready event like this:

fd.spRendered(function(){
    fd.field('ContentType').ready().then(() => {
        $(fd.field('ContentType').$el).find('option[value="0x010019ACC57FBA4146AFA4C822E719824BED00232610CE21944E44804BBCE51382EA88"]').remove();
    })
});

It works! Thank you both!

1 Like