I can't seem to get the prevalues, from a dropdownbox (no prevalue source, just the dropdown values) through the API. Whenever I try, the field.preValues.Count is 0. Am I looking in the wrong place?
I did this the other day! To get the prevalues for a checkbox list (its the same for any prevalue list I think). Here's my code (field is a reference to a contour field):
PreValueStorage test = new PreValueStorage();
List<Umbraco.Forms.Core.PreValue> pre = test.GetAllPreValues(field);
As a short note, if you have multiple PreValues using the same PreValueSourceType you may get wrong values from the GetPreValues method if you do not explicitly call f.PreValueSource.Type.LoadSettings(f.PreValueSource); first.
Getting prevalues through the API
I can't seem to get the prevalues, from a dropdownbox (no prevalue source, just the dropdown values) through the API. Whenever I try, the field.preValues.Count is 0. Am I looking in the wrong place?
I did this the other day! To get the prevalues for a checkbox list (its the same for any prevalue list I think). Here's my code (field is a reference to a contour field):
PreValueStorage test = new PreValueStorage();
List<Umbraco.Forms.Core.PreValue> pre = test.GetAllPreValues(field);
//DO STUFF WITH PREVALUES HERE
test.Dispose();
Comment author was deleted
@Tim, that will only work for standard prevalues, to get the prevalues independent of the type do:
field.PreValueSource.Type.GetPreValues(field)
@Tim, awesome, I wasn't aware of that method, I'll update my code to use that one instead!
:)
Just what the doctor ordered! Thank you Tim & Tim ;-)
As a short note, if you have multiple PreValues using the same PreValueSourceType you may get wrong values from the GetPreValues method if you do not explicitly call f.PreValueSource.Type.LoadSettings(f.PreValueSource); first.
This is per instructions from Tim, see http://our.umbraco.org/forum/umbraco-pro/contour/13937-API-not-returning-correct-prevalues-for-Field
Cheers,
Harald
is working on a reply...