Copied to clipboard

Flag this post as spam?

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


  • Sebastian Dammark 537 posts 1222 karma points
    Apr 26, 2020 @ 09:19
    Sebastian Dammark
    0

    ColorPicker returns JSON in Razor template

    I'm running 7.15.4, and I have ColorPicker property that returns JSON

    { "label": "White", "value": "ffffff" }
    

    According to the documentation Model.PropertyName should return the hexValue, but in this case I just get the JSON.

    Is there a workaround ?

    Documentation: https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Color-Picker/

  • Marc Goodson 1246 posts 8422 karma points MVP 5x c-trib
    Apr 26, 2020 @ 14:49
    Marc Goodson
    100

    Hi Sebastian

    There are a few inconsistencies with the colour picker and the last few releases of Umbraco 7...

    I had similar difficulties ended up with this

    //  var textColour = slide.HasValue("textColour") ? slide.GetPropertyValue<ColorPickerValueConverter.PickedColor>("textColour") : default(ColorPickerValueConverter.PickedColor);
                        var textColourRaw = slide.GetPropertyValue<string>("textColour");
                        var textColour = !String.IsNullOrEmpty(textColourRaw) ? JsonConvert.DeserializeObject<JObject>(textColourRaw) : default(JObject);
                        var textColourClass = "text-white";
                        if (textColour != null && textColour["label"].ToString() != "White")
                        {
                            textColourClass = "text-carousel-" + textColour["label"].ToString().ToUrlSegment();
                        }
    

    But that was in 7.14

    The commented out line that uses the property value converter may just work in 7.15

    Regards

    Marc

  • Sebastian Dammark 537 posts 1222 karma points
    Apr 26, 2020 @ 16:35
    Sebastian Dammark
    0

    That's excellent Marc, it put me in the right direction and solved my problem.

    I still couldn't use the property value converter, but I might have tried the wrong way :)

Please Sign in or register to post replies

Write your reply to:

Draft