Copied to clipboard

Flag this post as spam?

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


  • Andrey Karandashov 23 posts 215 karma points c-trib
    Nov 15, 2019 @ 14:21
    Andrey Karandashov
    0

    How to create a dynamic pre value source for dropdown\multi-dropdown?

    Hi.

    I created my own PreValueSource for the drop-down list, but I want to update this data every time the user opens the page.

     public class SportsPreValueSourceType : FieldPreValueSourceType
    {
        public SportsPreValueSourceType()
        {
            Id = new Guid("104def6e-75d5-4e41-bdba-8a4983fa4a8f");
            Name = "Sports list";
            Description = "List of the sports that depends on member";
        }
        public override List<PreValue> GetPreValues(Field field, Form form)
        {
            var helper = Umbraco.Web.Composing.Current.UmbracoHelper;
            var randomValue = new Random().Next(0, 1000);
    
            var preValue = randomValue > 500 ? ">500" : "<500";
    
            return new List<PreValue>() { new PreValue() { Id = 0, SortOrder = 0, Value = preValue } };
        }
    
        public override List<Exception> ValidateSettings()
        {
            var exs = new List<Exception>();
    
            return exs;
        }
    }
    

    How I can do that?

Please Sign in or register to post replies

Write your reply to:

Draft