扩展 Sitecore WFFM 字段类型

Extend Sitecore WFFM field type

我想向 WFFM 表单字段类型添加额外的属性。

内置字段类型在表单设计器左侧具有属性

我想在此区域中添加我自己的部分和属性。 这是否可以在不覆盖现有字段类型或修改核心代码的情况下轻松完成?

我真的不想重新创建例如单行文本字段只是为了添加我自己的属性字段。

不幸的是,实现它的唯一方法是在实现现有字段的代码中创建自定义Field Type,例如Single Line Text。没有其他配置可以更改,您必须通过代码添加属性,能够采用和扩展 'core' 代码是 Sitecore 的特色。

但是添加这些属性真的很简单,如果你只实现现有的属性,就不必重新开发每个字段。然后只需从 Type 下拉列表中 select 您的自定义单行文本,然后查看您的新属性..

实施现有的 Fields 将为您提供 Single Line Text 开箱即用的所有属性,现在您需要在新的 class 中定义属性。属性本身是 class 的 public properties,用视觉属性装饰。

例如,我想要一个属性来保存 FileUpload 字段的文件大小限制,这可以通过添加 public string 属性 来完成;

public class CustomSingleLineText : SingleLineText
{
    private int _fileSizeLimit;

    // Make it editable
    [VisualFieldType(typeof(EditField))]
    // The text display next to the attribute
    [VisualProperty("Max file size limit (MB) :", 5)]
    // The section the attribute appers in
    [VisualCategory("Appearance")]
    public string FileSizeLimit
    {
        get
        {
            return this._fileSizeLimit.ToString();
        }
        set
        {
            int result;
            if (!int.TryParse(value, out result))
                result = 5;
            this._fileSizeLimit = result;
        }
    }

然后,您可以通过从 FieldItem - FieldItem["Parameters"] 的 Parameters 中获取内容编辑器在提交时甚至验证器中输入的属性值来访问它

有关完整的示例来源,请参阅此 post;

http://jonathanrobbins.co.uk/2015/10/06/sitecore-marketplace-module-secure-file-upload/