Car*_*mas 5 sitecore web-forms-for-marketers sitecore8
我想为WFFM表单字段类型添加其他属性.
我想将自己的部分和属性添加到此区域.这可以轻松完成而不会覆盖现有的字段类型或使用核心代码进行黑客攻击吗?
我真的不想重新创建例如单行文本字段,只是为了添加我自己的属性字段.
不幸的是,实现它的唯一Field Type
方法是在代码中创建一个自定义来实现现有的字段,例如Single Line Text
。没有其他配置可以更改,您必须通过代码添加属性,能够采用和扩展“核心”代码是 Sitecore 的出名之处。
但添加这些属性非常简单,如果您只实现现有的属性,则不必重新开发每个字段。然后只需从下拉列表中选择您的自定义单行文本Type
并查看您的新属性。
实现现有的Fields
将为您提供Single Line Text
开箱即用的所有功能及其属性,现在您需要在新的class
. 属性本身是public properties
用视觉属性装饰的类的。
例如,我想要一个属性来保存FileUpload
字段的文件大小限制,这可以通过添加公共属性来完成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;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以访问内容编辑器在提交时输入的属性值,甚至可以通过从 - FieldItem["Parameters"] 获取属性值来访问Parameters
验证FieldItem
器
有关完整的示例来源,请参阅这篇文章;
http://jonathanrobbins.co.uk/2015/10/06/sitecore-marketplace-module-secure-file-upload/
归档时间: |
|
查看次数: |
559 次 |
最近记录: |