Sitecore 营销人员Web表单(WFFM)自定义字段类型的可视字段不显示
我使用以下代码向表单设计器添加了两个属性,但它们不会显示。字段类型类似于Sitecore.Form.Web.UI.Controls.CheckboxList,我需要它显示相同的属性。不幸的是,我不能进入这段代码,模块没有抛出任何错误,所以我觉得我错过了一些简单的东西Sitecore 营销人员Web表单(WFFM)自定义字段类型的可视字段不显示,sitecore,web-forms-for-marketers,Sitecore,Web Forms For Marketers,我使用以下代码向表单设计器添加了两个属性,但它们不会显示。字段类型类似于Sitecore.Form.Web.UI.Controls.CheckboxList,我需要它显示相同的属性。不幸的是,我不能进入这段代码,模块没有抛出任何错误,所以我觉得我错过了一些简单的东西 public class CheckBoxListPipedField : Sitecore.Forms.Mvc.Models.Fields.CheckBoxListField { [VisualCategory("List
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)));
}
}
公共类CheckBoxListPipedField:Sitecore.Forms.Mvc.Models.Fields.CheckBoxListField
{
[视觉分类(“列表”)]
[VisualFieldType(typeof(Sitecore.Form.Core.Visual.ListField))]
[视觉属性(“项目:”,100)]
公共ListItemCollection ListItems{get;set;}
[视觉分类(“列表”)]
[VisualFieldType(typeof(MultipleSelectedValueField))]
[视觉属性(“选定值:”,200)]
公共ListItemCollection SelectedValue{get;set;}
公共CheckBoxListPipedField(项目):基础(项目)
{
}
公共覆盖ControlResult GetResult()
{
var值=新列表();
StringBuilder stringBuilder1=新的StringBuilder();
如果(this.Items!=null)
{
foreach(SelectListItem选择中的ListItem
来自此中的项。项
其中项目。已选定
选择项目)
{
Value.Add(selectListItem.Value);
stringBuilder1.AppendFormat(“{0},”,selectListItem.Text);
}
}
var results=string.Join(“|”,值);
返回新的ControlResult(base.ID.ToString(),base.Title,results,stringBuilder1.ToString(0,(stringBuilder1.Length>0?stringBuilder1.Length-2: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;
}
有问题的代码没有问题。我忽略了将程序集和类添加到新的字段类型,只设置了MVC类型 您是否尝试过从
Sitecore.Form.Web.UI.Controls.CheckboxList
而不是Sitecore.Forms.Mvc.Models.Fields.CheckBoxListField
继承?。
[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;
}
}