Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely CMS
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

You can create a page with a shared content editor for any .NET object with a generic object editing system in Episerver. This topic explains how to register a custom editor for a specific type. 

Examples

The following example demonstrates how to register a custom editor. To create the actual editor, see Creating an Editor Widget.

C#
using EPiServer.Core;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;

namespace CodeSamples.EPiServerShell.EditorDescriptors
{
    /// <summary>
    /// Editor descriptor that will create a checkbox to be able to edit boolean values.
    /// </summary>
    [EditorDescriptorRegistration(TargetType = typeof(bool))]
    public class BooleanEditorDescriptor : EditorDescriptor
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BooleanEditorDescriptor"/> class.
        /// </summary>
        public BooleanEditorDescriptor()
        {
            //The default editing class that will be used in forms editing mode.
            ClientEditingClass = "dijit/form/CheckBox";
        }
    }
}

You also can define settings for the editor you want to use as shown in the following example.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using EPiServer.Editor;
using EPiServer.Shell;
using EPiServer.Shell.ObjectEditing;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;

namespace CodeSamples.EPiServerShell.EditorDescriptors
{
    /// <summary>
    /// Editor descriptor that will create a select input to be able to edit float number values
    /// </summary>
    [EditorDescriptorRegistration(TargetType = typeof(float))]
    public class FloatNumberEditorDescriptor : EditorDescriptor
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyFloatNumberEditorDescriptor"/> class.
        /// </summary>
        public FloatNumberEditorDescriptor()
        {
            //The default editing class that will be used in forms editing mode.
            ClientEditingClass = "dijit/form/NumberTextBox";
        }

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

            if (!attributes.OfType<RangeAttribute>().Any())
            {
                var constraints = new Dictionary<string, object>() 
                {
                    {"min", Double.MinValue },
                    {"max", Double.MaxValue }
                };
                //These settings will be passed to the constructor of the editor widget.
                metadata.EditorConfiguration.Add("constraints", constraints);
            }

            //Define what kind of editor we want to have, in this case we want to create an inline editor. This is used
            //when the user is in "on page editing" mode.
            metadata.CustomEditorSettings["uiWrapperType"] = UiWrapperType.Inline;
            //Specify the class for a custom editor responsible for the actual editing.
            //If not defined the default (forms) editor will be used.
            metadata.CustomEditorSettings["uiType"] = "dijit/form/NumberTextBox";
        }
    }
}

Related topics

Do you find this information helpful? Please log in to provide feedback.

Last updated: Sep 21, 2015

Recommended reading