From 49a81067e25a50ba8145be9e68faa04746bffa2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Kottal?= Date: Mon, 15 May 2023 14:02:18 +0200 Subject: [PATCH] Adds info about DataListItem attribute (#321) * Adds info about DataListItem attribute I needed a way to extend the information about enums in data lists, and found it in the source code. So why not add some documentation? :) --- docs/data-sources/data-source--enum.md | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/data-sources/data-source--enum.md b/docs/data-sources/data-source--enum.md index 98dc5863..09358207 100644 --- a/docs/data-sources/data-source--enum.md +++ b/docs/data-sources/data-source--enum.md @@ -22,3 +22,38 @@ Select the desired enumeration, by selecting the containing .NET assembly, and t The value returned from the List editor is the configured enumeration type. Depending on the `List editor` used, this may be wrapped in a `List`. + +##### Controlling Enum display + +You can use the [DataListItemAttribute](../../src/Umbraco.Community.Contentment/DataEditors/DataList/DataListItemAttribute.cs) to decorate your enum values with additional information for use with Contentment. With this attribute, you can specify properties such as name, description, icon, etc., for individual enum items. + +For example: + +```csharp +using Umbraco.Community.Contentment.DataEditors; + +public enum MyEnum +{ + [DataListItem(Description = "This is the first value", Group = "Group A", Icon = "icon-first")] + First, + + [DataListItem(Description = "This is the second value", Group = "Group B", Icon = "icon-second")] + Second, + + [DataListItem(Description = "This is the third value", Group = "Group A", Icon = "icon-third")] + Third +} +``` + +The `DataListItemAttribute` contains the following properties: + +| Property | Description | Type | +|-------------|------------------------------------------------------------------|---------| +| Description | Provides a description for the Enum value | string | +| Disabled | Specifies whether the Enum value should be disabled | bool | +| Group | Assigns the Enum value to a specific group | string | +| Icon | Specifies an icon for the Enum value | string | +| Ignore | Indicates whether the Enum value should be ignored | bool | +| Name | Provides a custom name for the Enum value (default: field name) | string | +| Value | Specifies a custom value for the Enum value (default: field value)| string | +