sitecore - 扩展 Sitecore WFFM 字段类型

标签 sitecore sitecore8 web-forms-for-marketers

我想向 WFFM 表单字段类型添加其他属性。

内置字段类型在表单设计器的左侧具有属性 enter image description here

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

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

最佳答案

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

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

实现现有的 Fields会给你一切Single Line Text开箱即用的属性,现在您需要在新的 class 中定义属性.属性本身是 public properties用视觉属性装饰你的类(class)。

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

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

然后,您可以通过从 Parameters 获取内容编辑器在提交或验证者中输入的属性值来访问它。的FieldItem - 字段项[“参数”]

有关完整示例源,请参见这篇文章;

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

关于sitecore - 扩展 Sitecore WFFM 字段类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33597747/

相关文章:

lucene - 使用Lucene和Sitecore获取锁失败

asp.net - Sitecore - Webforms for Marketers 2.3 - 将新表单插入页面

c# - 如何更改 Sitecore 登录页面上的消息?

sitecore - 如何在Sitecore中添加用户控件?

c# - 为什么我的 Sitecore.Context.Language 在 Controller 中重置?

asp.net - Sitecore:如何以及为何使用 CD 中的 Sitecore 虚拟用户(内容交付)

Sitecore - 营销人员网络表单 - 使用 ReadQueryString 选项

sitecore - 营销人员使用网络表单的条件字段?

c# - 我如何知道哪个 DMS 规则称为 Sitecore 组件?

solr - Sitecore Solr 重建核心功能导致 'Could not create instance'