Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Nicholas Westby 1711 posts 5631 karma points c-trib
    Aug 10, 2017 @ 23:19
    Nicholas Westby

    Ditto Processor for Drop Down Multiple?

    I've got a drop down multiple that allows content editors to select multiple days of the week (e.g., "Monday" and "Tuesday"). If I do this:

    public IEnumerable<string> Days { get; set; }

    The value doesn't seem to get set because the result of [UmbracoProperty] is a string (e.g., "Monday,Tuesday"). Is there a built in processor to return a collection of strings for a drop down multiple?

  • Nicholas Westby 1711 posts 5631 karma points c-trib
    Aug 10, 2017 @ 23:39
    Nicholas Westby

    I think I know the answer to this:

    It appears that Umbraco's default behavior is to return a single string. Suppose I'll just create a processor to split the string based on commas. Not ideal, but what're you gonna do.

  • Lee Kelleher 3774 posts 13946 karma points MVP 8x admin c-trib
    Aug 11, 2017 @ 06:47
    Lee Kelleher

    Yeah, we had to roll our own processor for this.

    using System;
    using System.Linq;
    using Umbraco.Core;
    namespace Our.Umbraco.Ditto
        public class DelimitedListAttribute : DittoProcessorAttribute
            protected string _delimiter;
            public DelimitedListAttribute(string delimiter = ",")
                _delimiter = delimiter;
            public override object ProcessValue()
                var strValue = Value == null
                    ? string.Empty
                    : Value.ToString();
                return string.IsNullOrWhiteSpace(strValue)
                    ? Enumerable.Empty<string>()
                    : strValue.Split(new[] { _delimiter }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(x => x.Trim())
                        .Where(x => !string.IsNullOrWhiteSpace(x))

    Funny thing is that we've only used it on one project so far.

    - Lee

Please Sign in or register to post replies

Write your reply to: