Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 07, 2010 @ 09:40
    Sebastiaan Janssen
    0

    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?

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Sep 07, 2010 @ 12:39
    Tim
    1

    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

    Sep 07, 2010 @ 13:31

    @Tim, that will only work for standard prevalues, to get the prevalues independent of the type do:

    field.PreValueSource.Type.GetPreValues(field)

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Sep 07, 2010 @ 13:46
    Tim
    0

    @Tim, awesome, I wasn't aware of that method, I'll update my code to use that one instead!

    :)

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Sep 07, 2010 @ 18:46
    Sebastiaan Janssen
    0

    Just what the doctor ordered! Thank you Tim & Tim ;-)

  • Harald Ulriksen 207 posts 249 karma points
    Oct 26, 2010 @ 13:09
    Harald Ulriksen
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft