Custom EPiServer key value property.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
JOS.PropertyKeyValueList.Ui Support for episerver 11 Nov 25, 2017
JOS.PropertyKeyValueList
.gitattributes
.gitignore
JOS.PropertyKeyValueList.sln
README.md

README.md

JOS.PropertyKeyValueList

Custom EPiServer key value list property with support for predefined keys.

Install it by simply running Install-Package JOS.PropertyKeyValueList.Ui in the Package manager console.

Inspired by this blogpost by Peter Löfman where he had done something quite similar to what I wanted to achieve so I used his blog post to get started.

The property has two "modes", ReadOnlyKeys or Normal.

ReadOnlyKeys

Add the property like this to try it out.

[BackingType(typeof(PropertyKeyValueList))]
[KeyValue(typeof(ReadOnlyKeysProvider))]
public virtual IEnumerable<KeyValueItem> ReadOnly { get; set; }

ReadOnlyMode is specified by passing in an IReadOnlyKeysProvider to the constructor of the KeyValueAttribute.

IReadOnlyKeysProvider

public interface IReadOnlyKeysProvider
{
    List<string> GetKeys();
}

My implementation in this example looks like this: ReadOnlyKeysProvider

public class ReadOnlyKeysProvider : IReadOnlyKeysProvider
{
    public List<string> GetKeys()
    {
        return new List<string>()
        {
            "Arsenal",
            "Real Madrid",
            "Barcelona",
            "Skara FC",
            "Axvalls IF",
            "Juventus",
            "IFK Göteborg",
            "Djurgårdens IF",
            "AIK"
        };
    }
}

When specifying a IReadOnlyKeysProvider the property will render in ReadOnlyKeysMode and look like this: Property rendered in readOnlyKeysMode The editor will only be able to edit the "value" portion of the property, not the predefined keys. It's not possible to add new items in this mode.

Normal

Add the property like this to try it out.

[BackingType(typeof(PropertyKeyValueList))]
[KeyValue]
public virtual IEnumerable<KeyValueItem> NotReadOnly { get; set; }

The property will look like this in edit mode: Property rendered in normal mode Currently it's possible to add as many items as you like but Im thinking of adding an optional MaxLimit.