Copied to clipboard

Flag this post as spam?

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


  • Bear 40 posts 129 karma points
    Jul 17, 2014 @ 16:54
    Bear
    1

    Prepopulate dropdown list for use in workflow

    Ok, I need to pre populate a drop down before I show it in a WorkflowType.

    Using the code below;

        [Umbraco.Forms.Core.Attributes.Setting("Method", description = "Testing", prevalues = "List 1,List 2,List 3", control = "Umbraco.Forms.Core.FieldSetting.Dropdownlist")]
        public string MadMimiMailingList { get; set; }
    

    Gives me;

    enter image description here

    Which is sort of what I want, but I want to show my own data dynamically. I know I can just change this value and it'd show me whatever I like - but the values I want to use are not constant or static.

    prevalues = "List 1,List 2,List 3"
    

    I can change this value and the dropdown changes, but I don't know how to set it dynamically - ideally I'd call a method that would give me a list of prevalues

    I have studied the infamous Country Dropdown, but that's for use within the forms, not on the actual workflow...

  • Kevin Lawrence 183 posts 350 karma points
    Jul 17, 2014 @ 17:52
    Kevin Lawrence
    104

    Is it possible to use the Settings method override?  Compile the settings in there and you should be able to dynamically build the PreValues.

    EDIT: You've probably worked it out by now but:

          public override Dictionary<string, Setting> Settings()
          {
             var settings = base.Settings();
             settings["Method"].prevalues = "test1,test2,test3";

             return settings;
          }

    Cheers

  • Bear 40 posts 129 karma points
    Jul 17, 2014 @ 19:02
    Bear
    3

    Thank you! The only bit I had to change was the settings["MadMimiMailingList"] to be the name of my property.

    The final, working code...

    [Setting("Mailing List", description = "Please select the MadMimi mailing list", prevalues = "List 1,List 2,List 3", control = "Umbraco.Forms.Core.FieldSetting.Dropdownlist")]
        public string MadMimiMailingList { get; set; }
    
        public override Dictionary<string, Setting> Settings()
        {
            var settings = base.Settings();
    
            // open new api
            var madMimiApi = new MadMimiApi();
    
            // try and get all the lists
            var allAvailableLists = madMimiApi.GetAllLists();
    
            var preValues = String.Join(",", (allAvailableLists.Select(list => list.Name).ToArray()));
    
            // add to prevalues
            settings["MadMimiMailingList"].prevalues = preValues;
    
            // done
            return settings;
        }
    
  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jul 18, 2014 @ 15:23
    Ismail Mayat
    0

    Wow that is awesome did not know you could do that!!!

  • Comment author was deleted

    Jul 21, 2014 @ 15:16

    Yeah same here :) awesome 

  • Comment author was deleted

    Jul 21, 2014 @ 15:17

    You could also create a custom field setting type, but guess this is easier 

  • antao 81 posts 371 karma points
    Mar 24, 2015 @ 14:47
    antao
    0

    Still concerning this, is it possible to get the name of the current form that has this workflow in this method?

    public override Dictionary

Please Sign in or register to post replies

Write your reply to:

Draft