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 :)
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
I'm not sure if this is the best way to do this, but a sample class that I've put together, returns the ID for a prevalue that matches a string value (e.g - the id for "Item1" in my dropdown list). It's a bit specific to my use case, but it retrieves the prevalues perfectly for me.
private readonly IDataTypeService _dataTypeService;
public DefaultComposer(IDataTypeService dataTypeService)
{
_dataTypeService = dataTypeService;
}
// Additional methods/logic can go here
// etc. etc.
// Returns the ID of the prevalue that matches the string value
private int GetDataTypePreValues(int id, string value)
{
var dataType = _dataTypeService.GetDataType(id); // The ID of the DataType you want to access
ValueListConfiguration prevalues = (ValueListConfiguration)dataType.Configuration;
int selected = 0;
if (prevalues != null && prevalues.Items != null && prevalues.Items.Any())
{
selected = prevalues.Items.Where(x => x.Value == value).Select(i => i.Id).FirstOrDefault();
}
return selected;
}
hello - is there an equivalent helper method of GetPreValueAsString in v8 yet? maybe on second thoughts we shouldn't be using it anyway as it results in a sql hit to get the prevalue.. from the cache would be better.
I got the prevalues for my dropdown field with this code.
@using Umbraco.Core.Services;
@using Umbraco.Core.PropertyEditors;
@{
IDataTypeService dataTypeService = Services.DataTypeService;
IDataType dataType = dataTypeService.GetDataType(1154); // Change number to your id from the data types section in backoffice
ValueListConfiguration prevalues = (ValueListConfiguration)dataType.Configuration;
foreach (ValueListConfiguration.ValueListItem item in prevalues.Items) {
<p>@item.Value</p>
}
}
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
and
but that is no longer possible to do :/
So any information on this would be of appreciated :)
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
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
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
Did anybody get to the bottom of this?
I'm not sure if this is the best way to do this, but a sample class that I've put together, returns the ID for a prevalue that matches a string value (e.g - the id for "Item1" in my dropdown list). It's a bit specific to my use case, but it retrieves the prevalues perfectly for me.
This is exactly the way we do it and it works.
hello - is there an equivalent helper method of GetPreValueAsString in v8 yet? maybe on second thoughts we shouldn't be using it anyway as it results in a sql hit to get the prevalue.. from the cache would be better.
Hi guys,
I got the prevalues for my dropdown field with this code.
Just stumbled across this myself, but think prevalue id's now aren't unique? as seeing cloud udas..
and another checkboxlist on the same site..
and values stored in the db are json.. jsut the value.
After lots of hunting around the code, the way that Umbraco 8 does this is
The first line just gets you the property editor for the DataType, the second line is the important one, it returns an IDictionary
This can be serialised into a json object
is working on a reply...