Try our conversational search powered by Generative AI!

The AllowedTypes attribute is not working in IList items

Vote:
 

Hello!

I have a page type with a property that is an IList of items (used for a navigation if that is of interest):

        [Display(
            Name = "Main navigation",
            Order = 100,
            GroupName = PropertyTabs.Header)]
        [EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<MainNavigationPropertyItem>))]
        public virtual IList<MainNavigationPropertyItem>? MainNavigation { get; set; }

The class used for the items contains a number of properties and also inherits another class in which there is a property of type ContentReference, to let the editor select pages to link to.

At the moment the editor can see all types of content in the selector. I want to limit it to only show pages, which can usually be done using  [AllowedTypes(typeof(PageData))]

I tried adding it in the same way as I would do for a property in a content model class:

public class MainNavigationPropertyItem : NavigationPropertyItem
{
  <...other properties>      
}

public class NavigationPropertyItem
{      
        [Required]
        [Display(Name = "Link to page", Order = 20)]
        [AllowedTypes(typeof(PageData))]
        public ContentReference? ContentLink { get; set; }
}

Although the AllowedTypes-attribute does not seem to work inside an IList?

Is this a bug? The Required and Display attribute that is on the same property is working.
Is there another way of making the select dialog only contain pages for a property in an IList?

Best regards,
Linda

#292914
Dec 09, 2022 13:52
Vote:
 

Hello Linda,

The validation of the AllowedTypes attribute does get validated, but it is actioned as part of the save event for the entire page and manifests within the feedback dot near the publish button:

If you are restricting to pages but don't care what type of page it is, then you can use the PageReference type instead of ContentReference and that will restrict the content types that you can select for the property.

#292917
Dec 09, 2022 14:57
Vote:
 

Thanks Mark!

We went for that option now, to use a PageReference instead, and it works well.
In the future there might be a need to also select files to have as a menu item, but we will cross that bridge when we get to it.

I thought that PageReference was obsolete by now. Or on its way to be at least. Any ideas of how long it will continue to live?

#293087
Dec 13, 2022 10:03
Vote:
 

Hi Linda,

Optimizely usually decorate objects and methods with the [Obsolete] attribute along with advice if something has been made obsolete.  In this case PageReference has not been decorated with an Obsolete attribute and is clearly still affecting UI with an intent.  There are a number of methods on PageReference and behaviours around remote servers which have been marked as Obsolete so perhaps they have just reigned in the level of functionality this property type has, but I would consider it safe to use.

#293088
Dec 13, 2022 10:13
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.