Web Forms For Marketers (WFFM) Visual Fields for custom Field Type not displaying

614 views Asked by At

I've used the following code to add two properties to Form Designer but they won't display. The field type is similar to Sitecore.Form.Web.UI.Controls.CheckboxList and I need it to display the same properties. Unfortunately I can't step into this code and the module isn't throwing any errors so I feel like I'm missing something simple.

public class CheckBoxListPipedField : Sitecore.Forms.Mvc.Models.Fields.CheckBoxListField
{
    [VisualCategory("List")]
    [VisualFieldType(typeof(Sitecore.Form.Core.Visual.ListField))]
    [VisualProperty("Items:", 100)]
    public ListItemCollection ListItems { get; set; }
    [VisualCategory("List")]
    [VisualFieldType(typeof(MultipleSelectedValueField))]
    [VisualProperty("Selected Value:", 200)]
    public ListItemCollection SelectedValue { get; set; }

    public CheckBoxListPipedField(Item item) : base(item)
    {

    }

    public override ControlResult GetResult()
    {
        var values = new List<string>();
        StringBuilder stringBuilder1 = new StringBuilder();
        if (this.Items != null)
        {
            foreach (SelectListItem selectListItem in
                from item in this.Items
                where item.Selected
                select item)
            {
                values.Add(selectListItem.Value);
                stringBuilder1.AppendFormat("{0}, ", selectListItem.Text);
            }
        }
        var results = string.Join("|", values);
        return new ControlResult(base.ID.ToString(), base.Title, results, stringBuilder1.ToString(0, (stringBuilder1.Length > 0 ? stringBuilder1.Length - 2 : 0)));
    }

} 
2

There are 2 answers

0
Amir Setoudeh On

Not sure why they wouldn't show up as the default code for the CheckboxListField doesn't have those, but try:

[TypeConverter(typeof(ListSelectItemsConverter))]
public override List<SelectListItem> Items
{
    get
    {
        return base.Items;
    }
    set
    {
        base.Items = value;
        if (this.Items != null)
        {
            this.Value = (
                from x in this.Items
                where x.Selected
                select x.Value).ToList<string>();
        }
    }
}

[ParameterName("selectedvalue")]
[PropertyBinder(typeof(ListFieldValueBinder))]
[TypeConverter(typeof(ListItemsConverter))]
public override object Value
{
    get;
    set;
}

You might be able to just set these to get { return base.Column }, etc, but here is how it looks on the base class.

[DefaultValue(1)]
public int Columns
{
    get;
    set;
}

[TypeConverter(typeof(StringToDirection))]
public Direction Direction
{
    get;
    set;
}

public int Rows
{
    get
    {
        if (this.Items.IsNullOrEmpty<SelectListItem>())
        {
            return 1;
        }
        int num = (this.Columns == 0 ? 1 : this.Columns);
        if (this.Items.Count % num <= 0)
        {
            return this.Items.Count / num;
        }
        return this.Items.Count / num + 1;
    }
}
0
Jason Davidson On

There was nothing wrong with the code in question. I neglected to add the assembly and class to the new Field Type, and had only set the MVC type.