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



我使用以下代码向窗体设计器添加了两个属性,但它们不会显示。字段类型类似于 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)));
    }
} 

不知道为什么它们不会显示为复选框列表字段的默认代码没有这些,但请尝试:

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

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

最新更新