This content is archived. See latest version here

Last updated: Feb 23 2015

You can create a page and shared-content editor for any .NET object with a generic object editing system that was introduced in EPiServer 7. The following example demonstrates how to register a custom editor for a specific type. 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.

Note: For information about the object editing system, see Object Editing.

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";
        }
    }
}

Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/