Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Feb 22, 2018 @ 14:55
    Martin
    0

    Color Picker - Return Label Value

    Hi All,

    Is it possible to return the Color Picker label value?

    Thanks

    Martin

  • David Peck 690 posts 1896 karma points c-trib
    Feb 22, 2018 @ 16:11
    David Peck
    0

    I bet you could using one or more of the DataTypeService. However you'll then be hitting the database, so if you're looking to do this on a page view I would find another route.

  • Tarik 196 posts 862 karma points c-trib
    Mar 07, 2019 @ 22:26
    Tarik
    0

    Martin, peace be upon those who follow guidance. I was able to get the label of selected value by using the following code.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Umbraco.Core.PropertyEditors.ValueConverters;
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = null;
    }
    @{
        var hexColor = Umbraco.Field("themeColor");
        String colorLabel = Model.Content.GetPropertyValue<ColorPickerValueConverter.PickedColor>("themeColor").Label;
    }
    

    Preview: enter image description here

  • Matthew Taylor 11 posts 85 karma points
    Jul 31, 2019 @ 13:14
    Matthew Taylor
    1

    This will work for Umbraco 8

            @if (Model.HasValue("yourColorPickerProperty"))
            {
                @* Include this after @inherits Umbraco.Web.Mvc.UmbracoViewPage on your Partial View *@
                @* @using Umbraco.Core.PropertyEditors.ValueConverters; *@
    
                var Colour = "#" + Model.Value<ColorPickerValueConverter.PickedColor>("yourColorPickerProperty");
                var Label = Model.Value<ColorPickerValueConverter.PickedColor>("yourColorPickerProperty").Label;
    
                <p style="color: @Colour">
                    The colour is @Label
                </p>
            }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies