Extend Field Type Sitecore WFFM

I would like to add additional attributes to the field type of the WFFM form.

Built-in field types have attributes to the left of the form designer enter image description here

I would like to add my section and attribute to this area. Can this be done without overwriting existing field types or hacking with the main code?

I really do not want to repeat the creation, for example. A single-line text field to add your own attribute field to it.

+5
source share
1 answer

Unfortunately, the only way to achieve this is to create a custom Field Type in code that implements an existing field, for example. Single Line Text . There is no other configuration where you need to change, you need to add your attributes using the code, the ability to take and extend the "main" code is what Sitecore knows.

But it’s very simple to add these attributes and not redo every field if you just implement existing ones. Then simply select your individual text for a single line in the Type drop-down list and view the new attributes.

Implementing the existing Fields will give you everything that Single Line Text will be ready with its attributes, now you need to define the attributes in your new class . The public properties attributes of your class, decorated with visual properties.

For example, I wanted the attribute to hold the file size limit in the FileUpload field, which can be done by adding the 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; } } 

Then you can access the attribute value entered by the Content Editor in the view or even valiadator by getting it from Parameters FieldItem - FieldItem ["Parameters"]

For a complete source example, see this post;

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

+3
source

Source: https://habr.com/ru/post/1235487/


All Articles