Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建项上的Sitecore WFFM复选框值_Sitecore - Fatal编程技术网

创建项上的Sitecore WFFM复选框值

创建项上的Sitecore WFFM复选框值,sitecore,Sitecore,我正在web表单中使用“创建项目保存”操作。我有一个复选框列表,指向包含类别项目的文件夹。这将映射到用户提交表单时将创建的项目模板上的多列表字段。但它传递的是复选框文本,而不是值,因此创建的每个新项的多重列表中都包含错误数据。有人知道如何设置复选框列表来传递值吗?我有点惊讶它一开始就这么做了。我还没有机会测试这个,但理论上,您可以创建一个新的字段类型,它继承自CheckboxList,我们称之为checkboxlistpipedvalue。代码如下所示: using System.Compone

我正在web表单中使用“创建项目保存”操作。我有一个复选框列表,指向包含类别项目的文件夹。这将映射到用户提交表单时将创建的项目模板上的多列表字段。但它传递的是复选框文本,而不是值,因此创建的每个新项的多重列表中都包含错误数据。有人知道如何设置复选框列表来传递值吗?我有点惊讶它一开始就这么做了。

我还没有机会测试这个,但理论上,您可以创建一个新的字段类型,它继承自
CheckboxList
,我们称之为
checkboxlistpipedvalue
。代码如下所示:

using System.ComponentModel;
using System.Linq;
using System.Text;
using Sitecore.Form.Core.Controls.Data;
using Sitecore.Form.Web.UI.Controls;

public class CheckboxListPipedValues : Sitecore.Form.Web.UI.Controls.CheckboxList
{
    [Browsable(false)]
    public override ControlResult Result
    {
        get
        {
            StringBuilder stringBuilder1 = new StringBuilder();
            var checkedItems = this.InnerListControl.Items.Where(a => a.Selected).ToList();
            var values = string.Join("|", checkedItems.Select(c => c.Value));
            foreach (var item in checkedItems)
            {
                stringBuilder1.AppendFormat("{0}, ", item.Text);
            }
            return new ControlResult(this.ControlName, values, stringBuilder1.ToString(0, (stringBuilder1.Length > 0 ? stringBuilder1.Length - 2 : 0)));
        }
    }
}
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Form.Core.Controls.Data;
using Sitecore.Forms.Core.Data;
using Sitecore.Forms.Mvc.Data.TypeConverters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Web.Mvc;


public class CheckBoxListPipedField : CheckBoxListField 
{
    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)));
    }
}
在Sitecore中,只需转到
/Sitecore/system/Modules/webforms for Marketers/Settings/Field Types/List Types/Checkbox List
,然后复制该项目。然后将程序集和类更改为新控件。更改表单以使用新字段,并确保正确映射值。现在,值的输出应该是一个以管道分隔的值列表,该列表应该可以很好地与multilist字段配合使用

编辑: 对于MVC,这是相同的过程,但是您需要更新字段类型项中的
MVC类型
,以指向您的新类。MVC的代码应该如下所示:

using System.ComponentModel;
using System.Linq;
using System.Text;
using Sitecore.Form.Core.Controls.Data;
using Sitecore.Form.Web.UI.Controls;

public class CheckboxListPipedValues : Sitecore.Form.Web.UI.Controls.CheckboxList
{
    [Browsable(false)]
    public override ControlResult Result
    {
        get
        {
            StringBuilder stringBuilder1 = new StringBuilder();
            var checkedItems = this.InnerListControl.Items.Where(a => a.Selected).ToList();
            var values = string.Join("|", checkedItems.Select(c => c.Value));
            foreach (var item in checkedItems)
            {
                stringBuilder1.AppendFormat("{0}, ", item.Text);
            }
            return new ControlResult(this.ControlName, values, stringBuilder1.ToString(0, (stringBuilder1.Length > 0 ? stringBuilder1.Length - 2 : 0)));
        }
    }
}
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Form.Core.Controls.Data;
using Sitecore.Forms.Core.Data;
using Sitecore.Forms.Mvc.Data.TypeConverters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Web.Mvc;


public class CheckBoxListPipedField : CheckBoxListField 
{
    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)));
    }
}
使用Sitecore.Data;
使用Sitecore.Data.Items;
使用Sitecore.Form.Core.Controls.Data;
使用Sitecore.Forms.Core.Data;
使用Sitecore.Forms.Mvc.Data.TypeConverters;
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用System.Linq;
使用System.Runtime.CompilerServices;
使用系统文本;
使用System.Web.Mvc;
公共类CheckBoxListPipedField:CheckBoxListField
{
公共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));
}
}

谢谢!我认为这会起作用,但我使用的是MVC,所以我需要对代码进行一些更改。我在选择checkedItems时遇到了一些问题。如果您对如何为MVC重新编写它有任何建议,我将不胜感激@JasonDavidson,我添加了MVC版本。让我知道这是否对你有效。好的,就快到了。2件事:Sitecore.Forms.Mvc.Data.TypeConverters不存在。应该是打字机吗?当我构建它时,会出现以下错误:Sitecore.Forms.Mvc.Models.Fields.CheckBoxListField不包含接受0个参数的构造函数。您应该能够添加如上更新的构造函数。至于
类型转换器
,我从Sitecore 8 dll获取了using语句。。您可以安全地删除using语句。如果没有,请告诉我您使用的是哪个版本的Sitecore,我会得到相应的更新。这正是我所做的,而且它正在工作!非常感谢你的帮助。