I just upgraded an Umbraco site from 7.11.1 to 7.14 and color picker seems to return a Json {"label": "hex","value": "hex"} irrespective of whether labels are enabled in the color picker datatype or not.
Now I have a helper class that takes the hex in a switch statement and return a color class, since the value returned is Json now, it fails. I can deserialize the Json and get label and value. But pages saved pre 7.14 return just a hex string while pages saved after 7.14 return the Json. Is this the expected behavior?
I upgraded from 7.12.4 to 7.14.0 and am experiencing the same issue. The colorpicker property returns just the hex string for older pages, but returns a json object string for new pages.
Exactly Color Picker has changed since v7.13. It no longer stores as Hex but JSON value. Please can you check below discussion on this topic and they have provided a fix for it too.
Apologies for the late response on my own post. My solution was similar to the one proposed but server side. I had a helper class that returned a css class name depending on the hex,
public static string GetColorClass(string hex)
{
if (!string.IsNullOrEmpty(hex))
{
if (hex.Length > 6)
{
JavaScriptSerializer j = new JavaScriptSerializer();
var c = j.Deserialize<ColorPickerJson>(hex);
if (c != null && !string.IsNullOrEmpty(c.value))
{
return GetColor(c.value);
}
}
else
{
return GetColor(hex);
}
}
return "white";
}
private static string GetColor(string hex)
{
switch (hex)
{
case "ffffff":
return "white";
case "00ac8f":
return "green";
case "f3f4f5":
return "grey";
case "22222e":
return "slate";
case "ff1a58":
return "pink";
default:
return "white";
}
}
ColorPickerJson is just a class I used for Deserialization
public class ColorPickerJson
{
public string label { get; set; }
public string value { get; set; }
}
This provided a neat backwards compatibility with content items wherecolor picker was used but wasn't saved back again after the Umbraco upgrade in which this change was introduced. Alternatively, if you saved back the content item, Umbraco would automatically save the json format back for the color picker.
ColorPicker
Hi All,
I just upgraded an Umbraco site from 7.11.1 to 7.14 and color picker seems to return a Json {"label": "hex","value": "hex"} irrespective of whether labels are enabled in the color picker datatype or not.
Now I have a helper class that takes the hex in a switch statement and return a color class, since the value returned is Json now, it fails. I can deserialize the Json and get label and value. But pages saved pre 7.14 return just a hex string while pages saved after 7.14 return the Json. Is this the expected behavior?
Any ideas will be much appreciated.
Bharani
I upgraded from 7.12.4 to 7.14.0 and am experiencing the same issue. The colorpicker property returns just the hex string for older pages, but returns a json object string for new pages.
Hi,
Exactly Color Picker has changed since v7.13. It no longer stores as Hex but JSON value. Please can you check below discussion on this topic and they have provided a fix for it too.
Issue:- https://github.com/umbraco/Umbraco-CMS/issues/3993
Solution:- https://our.umbraco.com/forum/using-umbraco-and-getting-started/95232-713-issues#comment-301098
Hope that helps.
Regards, Shaishav
Hi All,
Apologies for the late response on my own post. My solution was similar to the one proposed but server side. I had a helper class that returned a css class name depending on the hex,
ColorPickerJson is just a class I used for Deserialization
This provided a neat backwards compatibility with content items wherecolor picker was used but wasn't saved back again after the Umbraco upgrade in which this change was introduced. Alternatively, if you saved back the content item, Umbraco would automatically save the json format back for the color picker.
Hope this helps!
Bharani
is working on a reply...