Copied to clipboard

Flag this post as spam?

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


  • Duncan Turner 3 posts 83 karma points
    1 week ago
    Duncan Turner
    0

    Prepopulate a FieldType in Umbraco forms

    I am trying to prepopulate a dropdownlist for the user at a PreValue stage in Umbraco forms. This data will come from an external source (API).

    I was initially thinking the you could provide data to the Settings method, but not having much luck and not sure that this is even the best approach?

    public class BusinessType : FieldType
    {
        [Setting("BusinessType", view = "BusinessType", prevalues = "", description = "Prepopulated Business Type Data")]
        public string BusType { get; set; } = "BusType";
        public BusinessType()
        {
            Name = "BusinessType";
            Id = new Guid("39034376-3c1a-41fa-9673-674512f9d109");
            Description = "This is an Business Type API feed";
            Icon = "icon-list";
            DataType = FieldDataType.String;
            SortOrder = 10;
        }
    
    
        public override Dictionary<string, Setting> Settings()
        {
            var settings = base.Settings();
    
            settings[BusType].prevalues = "One, Two, Three, Four, Five";
    
            return settings;
        }
    
    
    
        public override IEnumerable<object> ProcessSubmittedValue(Field field, IEnumerable<object> postedValues, HttpContextBase context)
        {          
            var values = new List<object>();
            var id = field.Id.ToString();
            var businessTypeName = context.Request[id + "BusinessTypeName"];
            var selection = string.Join(", ", businessTypeName);
            values.Add(selection);
            return values;
        }
    
    }
    
  • Owain Williams 411 posts 1216 karma points MVP 3x c-trib
    1 week ago
    Owain Williams
    0

    Hey mate, One suggestion that was given on Twitter was "Needs to be a prevalue source type".

    https://our.umbraco.com/documentation/add-ons/umbracoforms/Editor/Defining-and-Attaching-Prevaluesources/Prevalue-source-types/

    Might help?

  • Tim Geyssens 6499 posts 15238 karma points MVP 2x c-trib
    1 week ago
  • Tim Geyssens 6499 posts 15238 karma points MVP 2x c-trib
    1 week ago
    Tim Geyssens
    100

    this can probably help: http://www.nibble.be/?p=217

  • Duncan Turner 3 posts 83 karma points
    1 week ago
    Duncan Turner
    0

    You've made my Monday.

    Thank you so much for that link... Solved my issue!

    I wish the documentation was a bit better than what it currently is...

Please Sign in or register to post replies

Write your reply to:

Draft