Copied to clipboard

Flag this post as spam?

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


  • Ólafur Hólm Eyþórsson 3 posts 94 karma points
    Mar 18, 2019 @ 18:04
    Ólafur Hólm Eyþórsson
    1

    V8 Prevalues from a specific data type

    Hi, how do i get the prevalues from a specific data type in v8 ?

    at my work place we've always been doing the example below in v7

    public static string GetPreValue(string id)
    {
       var value = string.Empty;
       if (!string.IsNullOrEmpty(id))
       {
           int preId = 0;
           var parse = Int32.TryParse(id, out preId);
    
           if (parse)
           {
               var helper = new UmbracoHelper(UmbracoContext.Current);
    
               value = helper.GetPreValueAsString(preId);
           }
       }
       return value;
    }
    

    and

    public List<SelectListItem> GetPreValuesFromDataTypeId(int dataTypeId)
            {
                List<SelectListItem> preValueSelectorList = new List<SelectListItem>();
    
                XPathNodeIterator iterator = umbraco.library.GetPreValues(dataTypeId);
                iterator.MoveNext();
                XPathNodeIterator preValues = iterator.Current.SelectChildren("preValue", "");
    
                while (preValues.MoveNext())
                {
                    string preValueIdAsString = preValues.Current.GetAttribute("id", "");
                    int preValueId = 0;
                    int.TryParse(preValueIdAsString, out preValueId);
                    string preValue = preValues.Current.Value;
                    preValueSelectorList.Add(new SelectListItem { Value = preValue, Text = preValue });
                }
    
                return preValueSelectorList;
            }
    

    but that is no longer possible to do :/

    So any information on this would be of appreciated :)

  • David Knittl 7 posts 107 karma points
    Mar 20, 2019 @ 12:10
    David Knittl
    0

    Hi,

    I have a similar problem. I also work with the prevalues of a dropdown field in my code. In v7 I accessed the prevalues through

    Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeId).PreValuesAsDictionary
    

    That's not working any more in v8. Now through debugging I found a property called "Configuration" on the IDataType interface. All prevalues are in there (I see them in debugging) and that object is of type

    Umbraco.Core.PropertyEditors.DropDownFlexibleConfiguration
    

    Now if I try to access this property and cast it to DropDownFlexibleConfiguration (or if I use the "ConfigurationAs

    Does anyone have an idea how to access the prevalues in v8?

    Cheers, David

Please Sign in or register to post replies

Write your reply to:

Draft