Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

SelectOne on PropertyValueList

$
0
0

I have an Episerver 11.3.1 site. I'm building a block that needs to store a list of strings, so I thougt this would be a perfect scenario for using the new property value list described here:  https://world.episerver.com/blogs/bartosz-sekula/dates/2017/10/property-value-list/

The problem is, I want each item in the list to be selected from a dropdown. Essentially, I want to apply the [SelectOne] attribute to each individual item in the list.

Here's what I tried. I created an editor descriptor for my property:

[EditorDescriptorRegistration(TargetType = typeof(IList<string>), UIHint = "ProductSpecList")]
public class ProductSpecListEditorDescriptor : PropertyValueListEditorDescriptor<string>

I did the following in the ModifyMetadata method override:

public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
{
    base.ModifyMetadata(metadata, attributes);

    if (metadata.CustomEditorSettings["innerPropertySettings"] is MetadataStoreModel model)
    {
        model.UiType = "epi-cms/contentediting/editors/SelectionEditor";
        var sf = new ProductSpecSelectionFactory();
        foreach (var item in sf.GetSelections(metadata))
        {
            model.Selections.Add(item);
        }
    }
}

I came up with that by comparing the json for two different properties (one a simple string with a SelectOne attribute, the other an IList<string>) coming back from the server after this ajax call:  /EPiServer/shell/Stores/metadata/EPiServer.Core.ContentData?modelAccessor=%7B%22contentLink%22%3A%22950_986%22%7D&dojo.preventCache=1516984334772

The list functionality works with this, but none of the items in the list have any sort of control - textbox, dropdown, or otherwise.

Is this even possible? I'd appreciate some help -- or if someone knows it definitively is not possible, I'd like to log it as a feature request. :)


Viewing all articles
Browse latest Browse all 9076

Trending Articles