SelectOne on PropertyValueList

Vote:
 

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), UIHint = "ProductSpecList")]
public class ProductSpecListEditorDescriptor : PropertyValueListEditorDescriptor

I did the following in the ModifyMetadata method override:

public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable 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) 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. :)

#187567
Jan 26, 2018 17:39
Vote:
 

If I understand the question correctly...

Have you tried using your own model/DTO in the property list, rather than a string -- with a SelectionFactory? 

Example...

public class SomePage : PageData
{
    [EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<SomeStringsModel>))]
    public virtual IList<string> SomeStrings { get; set; }
}

[PropertyDefinitionTypePlugIn]
public class SomeStringsPropertyList : PropertyList<SomeStringsModel>
{
    public override PropertyData ParseToObject(string value)
    {
        this.ParseToSelf(value);
        return this;
    }

    protected override SomeStringsModel ParseItem(string value)
    {
        return JsonConvert.DeserializeObject<SomeStringsModel>(value);
    }
}

public class SomeStringsModel
{
    [SelectOne(SelectionFactoryType = typeof(SomeStringSelectionFactory))]
    public virtual string SomeString { get; set; }
}

public class SomeStringSelectionFactory : ISelectionFactory
{
    public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
    {
        // return your selections here
        return new[] {"Selection 1", "Selection 2"}.Select(x => new SelectItem { Text = x, Value = x });
    }
}
#187573
Edited, Jan 27, 2018 15:53
* 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.