Copied to clipboard

Flag this post as spam?

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


  • Christian Palm 278 posts 273 karma points
    Sep 07, 2010 @ 14:40
    Christian Palm
    0

    Using custom FieldSettingType on custom FieldType

    When using a custom FieldSettingType on a custom FieldType i get an exception.

    When I add the custom FieldType to a form the setting are working.
    But after the form has been saved in can not be opened since an exception are being thrown.

    It seems like it can not set the custom FieldSettingType

    Here is the exception

    [MissingMethodException: Method 'Upac.CampaignMonitor.ContourExtensions.ListsFieldType.Lists to include' not found.]
    System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) +2172
    Umbraco.Forms.Core.FieldType.LoadSettings(List`1 settings) in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.Core\FieldType.cs:86
    Umbraco.Forms.Data.Storage.FieldStorage.GetAllFields(FieldSet fieldset) in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.Core\Data\FormStorage\FieldStorage.cs:96
    Umbraco.Forms.Data.Storage.FieldSetStorage.GetAllFieldSets(Page page) in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.Core\Data\FormStorage\FieldSetStorage.cs:42
    Umbraco.Forms.Data.Storage.PageStorage.GetAllPages(Form form) in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.Core\Data\FormStorage\PageStorage.cs:41
    Umbraco.Forms.Data.Storage.<>c__DisplayClass9.<GetForm>b__8() in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.Core\Data\FormStorage\FormStorage.cs:133
    umbraco.cms.businesslogic.cache.Cache.GetCacheItem(String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) +213
    umbraco.cms.businesslogic.cache.Cache.GetCacheItem(String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) +121
    umbraco.cms.businesslogic.cache.Cache.GetCacheItem(String cacheKey, Object syncLock, CacheItemRemovedCallback refreshAction, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) +118
    Umbraco.Forms.Core.Services.CacheService.GetCacheItem(String cacheKey, Object syncLock, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.Core\Services\CacheService\CacheService.cs:62
    Umbraco.Forms.Data.Storage.FormStorage.GetForm(Guid id) in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.Core\Data\FormStorage\FormStorage.cs:124
    Umbraco.Forms.UI.Pages.editForm.Page_Load(Object sender, EventArgs e) in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.UI\Pages\editForm.aspx.cs:32
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
    System.Web.UI.Control.OnLoad(EventArgs e) +99
    umbraco.BasePages.BasePage.OnLoad(EventArgs e) +49
    System.Web.UI.Control.LoadRecursive() +50
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

    BTW the custom FieldSettingType works perfectly on my custom FieldPreValueSourceType

    The source code

    namespace Upac.CampaignMonitor.ContourExtensions
    {
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.UI.WebControls;

    using CampaignMonitorAPIWrapper.CampaignMonitorAPI;

    using Umbraco.Forms.Core;
    using Umbraco.Forms.Core.Controls;

    public class ListsFieldType : FieldType
    {
    #region Fields

    private ValidateableCheckBoxList cbl;
    private List<object> value;

    #endregion Fields

    #region Constructors

    public ListsFieldType()
    {
    base.Id = new Guid("{46172748-DF31-4c14-B4F3-300E355606A8}");
    base.Name = "Campaign Monitor Lists";
    base.Description = "Renders a checkbox list with mailinglists";
    this.Icon = "checkboxlist.png";
    this.DataType = FieldDataType.String;
    this.value = new List<object>();
    }

    #endregion Constructors

    #region Properties

    public override WebControl Editor
    {
    get
    {
    cbl = new ValidateableCheckBoxList();
    cbl.CssClass = "checkboxlist";
    cbl.RepeatLayout = RepeatLayout.Flow;

    ListItem[] items = GetListItems();
    cbl.Items.AddRange(items);
    return cbl;
    }
    set
    {
    base.Editor = value;
    }
    }

    [Umbraco.Forms.Core.Attributes.Setting("Lists to include", description = "The selected lists the user can subscribe to", control = "Upac.CampaignMonitor.ContourExtensions.ListsFieldSetting", assembly = "Upac.CampaignMonitor")]
    public string ListsToInclude
    {
    get;
    set;
    }

    public override List<object> Values
    {
    get
    {
    if (cbl != null && cbl.SelectedIndex > -1)
    {
    value.Clear();
    foreach (ListItem item in cbl.Items)
    {
    if (item.Selected)
    {
    value.Add(item.Value);
    }
    }
    }
    return value;
    }
    set
    {
    this.value = value;
    }
    }

    #endregion Properties

    #region Methods

    public override string RenderPreview()
    {
    return "<div class=\"checkboxlist\"></div>";
    // More to come
    }

    public override string RenderPreviewWithPrevalues(List<object> prevalues)
    {
    return "<div class=\"checkboxlist\"></div>";
    // More to come
    }

    private ListItem[] GetListItems()
    {
    List<ListItem> items = new List<ListItem>();
    if (!string.IsNullOrEmpty(ListsToInclude))
    {
    string[] selectedValues = ListsToInclude.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
    Api api = new Api();
    List<List> lists = api.GetLists();
    foreach (string selectedValue in selectedValues)
    {
    List firstOrDefault = lists.FirstOrDefault(s => s.ListID == selectedValue);
    if (firstOrDefault != null)
    {
    ListItem listItem = new ListItem(firstOrDefault.Name, firstOrDefault.ListID)
    {
    Selected = value.Contains(firstOrDefault.ListID)
    };
    items.Add(listItem);
    }
    }
    }
    return items.ToArray();
    }

    #endregion Methods
    }
    }
  • Comment author was deleted

    Sep 07, 2010 @ 14:45

    Hi Christian,

    I only tested it with a custom workflow (which worked), will check this out later today.

    Cheers,
    Tim

  • Comment author was deleted

    Sep 07, 2010 @ 15:27

    Ok found and fixed the problem,

    It's the /usercontrols/UmbracoContour/EditForm.ascx that needed an update

    you can download the update from our build server http://nightly.umbraco.org/Umbraco Contour/ (use the latest build of the work in progress version) and simply replace the /usercontrols/UmbracoContour/EditForm.ascx file

    Or you could update the file on line 303

    change

    ((System.Collections.Generic.KeyValuePair<string, Umbraco.Forms.Core.Attributes.Setting>)Container.DataItem).Value.GetName()

    to

    ((System.Collections.Generic.KeyValuePair<string, Umbraco.Forms.Core.Attributes.Setting>)Container.DataItem).Key
  • Christian Palm 278 posts 273 karma points
    Sep 08, 2010 @ 10:29
    Christian Palm
    0

    Perfect

  • Peter Drayton 29 posts 49 karma points
    Oct 26, 2011 @ 16:23
    Peter Drayton
    0

    Hi,

     

    I'm trying to do something similar with MailChimp, but I couldn't get your code to work.

    This line:

    List<List> lists = api.GetLists();

    is causing me issues in Visual Studio, it reports an Error saying 

       Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments   

     

    Any help much appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft