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 32 posts 135 karma points
    Jun 27, 2020 @ 11:59
    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 481 posts 1413 karma points MVP 7x c-trib
    Jun 27, 2020 @ 14:53
    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?

  • Comment author was deleted

    Jun 29, 2020 @ 07:08
  • Comment author was deleted

    Jun 29, 2020 @ 07:09

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

  • Duncan Turner 32 posts 135 karma points
    Jun 29, 2020 @ 08:26
    Duncan Turner
    1

    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