营销人员的Web表单(WFFM)自定义字段类型的可视字段不显示

时间:2015-06-11 23:25:07

标签: sitecore web-forms-for-marketers

我已使用以下代码向表单设计器添加两个属性,但它们不会显示。字段类型类似于Sitecore.Form.Web.UI.Controls.CheckboxList,我需要它来显示相同​​的属性。不幸的是,我无法进入此代码,模块不会抛出任何错误,所以我觉得我错过了一些简单的东西。

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 个答案:

答案 0 :(得分:0)

不确定为什么它们不会出现,因为CheckboxListField的默认代码没有,但请尝试:

[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;
}

您可以将它们设置为get { return base.Column }等,但这是它在基类上的外观。

[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;
    }
}

答案 1 :(得分:0)

有问题的代码没有任何问题。我忽略了将程序集和类添加到新的Field Type,并且只设置了MVC类型。