Copied to clipboard

Flag this post as spam?

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

  • MB 108 posts 397 karma points
    Apr 17, 2019 @ 01:16

    Fetch color-values for data-type based on Umbraco Color Picker?

    I have a Data-Type 'My Colors' that is based on the Umbraco Color Picker property editor.

    I want to be able to fetch the current list of colors from the Data-Type, so I can perform some comparison tests with another value I have, and take appropriate actions.

    How to drill-down into the Data-Type and fetch the values for this is totally eluding me at the moment.

  • Dave de Moel 121 posts 571 karma points c-trib
    Apr 17, 2019 @ 13:23
    Dave de Moel

    You need to use the DataTypeService for that:

    var service =  ApplicationContext.Current.Services.DataTypeService

    Then you can easily get your color picker by using:

    var colorPicker = service.GetDataType("My Colors")

    And in that you should have a configuration property with a list of your colors in a json format. enter image description here

  • MB 108 posts 397 karma points
    Apr 17, 2019 @ 22:23

    Thanks for that.

    I'd gotten part-way there with using the same reference to the current DataTypeService, but there is no GetDataType(name) function I can see, and GetDataTypeDefinitionByName(String) does not seem to provide me with a Configuration property.

    However, that made me stop and think about what I was trying to do, and with a bit more API sleuthing, I decided that what I needed for this case is perhaps something along these lines:

    var dataTypeService = ApplicationContext.Current.Services.DataTypeService;
    var dataType = dataTypeService.GetDataTypeDefinitionByName("My Colors");
    var dataTypeId = dataType.Id;
    var dataTypePreValues = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeId).PreValuesAsDictionary;

    Anyways... at the moment I seem to have a dictionary of values, which should keep my busy for a while.

    prevalues dictionary

Please Sign in or register to post replies

Write your reply to: