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 276 posts 271 karma points
    Sep 03, 2010 @ 14:21
    Christian Palm
    0

    How to create a new FieldSettingType

    Is there any example or documentation on how to create your own FieldSettingType?

    I need a CheckBoxList

    This is what I have so fare

    public class ListsFieldSetting : FieldSettingType
    {
    private CheckBoxList cbl;
    private string val;

    public ListsFieldSetting()
    {
    cbl = new CheckBoxList();
    val = string.Empty;
    }

    public override WebControl RenderControl(Setting setting, Form form)
    {
    // What to do?
    }

    public override string Value
    {
    get
    {
    // What to do?
    }
    set
    {
    // What to do?
    }
    }
    }
  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Sep 03, 2010 @ 15:20
    Tim Geyssens
    0

    Hi Christian,

    Good point, we'll add this to the dev docs and the shared source for now here is the sourcecode for the textfield fieldsetting type

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.UI.WebControls;

    namespace Umbraco.Forms.Core.FieldSetting
    {
    public class TextField : FieldSettingType
    {
    private TextBox tb = new TextBox();

    public override string Value
    {
    get
    {
    return tb.Text;
    }
    set
    {
    tb.Text = value;
    }
    }

    public override System.Web.UI.WebControls.WebControl RenderControl(Attributes.Setting sender, Form form)
    {
    tb.ID = sender.GetName();
    tb.TextMode = TextBoxMode.SingleLine;
    tb.CssClass = "guiInputText guiInputStandardSize";


    if (string.IsNullOrEmpty(tb.Text) && Prevalues.Count > 0)
    tb.Text = Prevalues[0];

    return tb;
    }
    }
    }

     

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Sep 03, 2010 @ 15:28
    Tim Geyssens
    0

    And this for the DocumentType picker

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Umbraco.Forms.Core.FieldSetting.Pickers {
    public class DocumentType : BasePicker {
    public DocumentType() {
    ObjectGuid = new Guid("a2cb7800-f571-4787-9638-bc48539a0efb");
    }
    }
    }

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Umbraco.Forms.Core.FieldSetting.Pickers {
    public class BasePicker : FieldSettingType {

    public Guid ObjectGuid { get; set; }

    private System.Web.UI.WebControls.DropDownList ddl = new System.Web.UI.WebControls.DropDownList();

    private string _val = string.Empty;

    public override string Value {
    get {
    return ddl.SelectedValue;
    }
    set {
    if (!string.IsNullOrEmpty(value))
    _val = value;
    }
    }

    public override System.Web.UI.WebControls.WebControl RenderControl(Attributes.Setting sender, Form form) {

    ddl.ID = sender.GetName();

    ddl.Items.Clear();
    List<KeyValuePair<String, String>> items = new List<KeyValuePair<String,String>>();

    if(ObjectGuid != Guid.Empty){
    Guid[] guids = umbraco.cms.businesslogic.CMSNode.getAllUniquesFromObjectType(ObjectGuid);
    foreach (Guid g in guids) {
    umbraco.cms.businesslogic.CMSNode node = new umbraco.cms.businesslogic.CMSNode(g);
    items.Add(new KeyValuePair<string, string>(node.Id.ToString(), node.Text));
    }
    }

    items.Sort(delegate(KeyValuePair<String, String> x, KeyValuePair<String, String> y) { return x.Value.CompareTo(y.Value); });

    foreach (KeyValuePair<String, String> kv in items) {
    ddl.Items.Add( new System.Web.UI.WebControls.ListItem(kv.Value, kv.Key));
    }

    System.Web.UI.WebControls.ListItem li = new System.Web.UI.WebControls.ListItem("Choose...", "");
    li.Selected = true;
    ddl.Items.Insert(0, li);

    ddl.SelectedValue = _val;

    return ddl;
    }

    }
    }

    Is that enough info to get you going?

  • Christian Palm 276 posts 271 karma points
    Sep 03, 2010 @ 15:33
    Christian Palm
    0

    Could it be possible that is can only load settings from Umbraco.Forms.Core and not from other assemblies ?

    I have tried your first example and it gives an exception

    [NullReferenceException: Object reference not set to an instance of an object.]
    Umbraco.Forms.UI.Pages.editPrevalues.LoadSettings() in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.UI\Pages\editPrevalueSource.aspx.cs:88
    Umbraco.Forms.UI.Pages.editPrevalues.Page_Load(Object sender, EventArgs e) in d:\TeamCity\buildAgent\work\e4473b9ec9597356\Umbraco.Forms.UI\Pages\editPrevalueSource.aspx.cs:50
    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
  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Sep 03, 2010 @ 15:41
    Tim Geyssens
    0

    @Christian,

    Yup looks like that is the case currently, untill we have an update ready, is the dropdownlist an option for you?

     [Attributes.Setting("DropdownlistTest", description = "Dropdownlist demo", control = "Umbraco.Forms.Core.FieldSetting.Dropdownlist", prevalues="first,second,third")]

     

     

     

     

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Sep 03, 2010 @ 16:06
    Tim Geyssens
    0

    Hi Christian,

    Just made the update that makes it possible to plug in custom field setting types

    If you upgrade to the latest build of the work in progress version (http://nightly.umbraco.org/Umbraco%20Contour/), and make sure you also add the assembly as a parameter

    [Umbraco.Forms.Core.Attributes.Setting("Custom test", description = "Custom test", control = "TestContourCustomFieldSettingType.TestFieldTypeSetting", assembly = "TestContourCustomFieldSettingType")]
    public string CustomTest { get; set; }

     

  • Christian Palm 276 posts 271 karma points
    Sep 07, 2010 @ 11:36
    Christian Palm
    0

    Hi Tim

    I Could not use the dropdownlist since the prevalues are comming from Campaign Monitor.

    I have downloaded the latest build and I can now add the assembly and it works perfectly :-)

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Sep 07, 2010 @ 13:32
    Tim Geyssens
    0

    Great, glad it works!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies