sitecore的共享字段营销人员的Web表单自定义字段属性

sitecore的共享字段营销人员的Web表单自定义字段属性,sitecore,sitecore8,web-forms-for-marketers,Sitecore,Sitecore8,Web Forms For Marketers,我将sitecore 8.1与MVC一起使用,我被要求在web表单中为具有占位符文本的营销人员提供单行文本和电子邮件字段。 我已经成功创建了一个带有占位符的自定义文本字段,但有一个小问题,即它不是共享字段或不支持多文化。 我关注了@azadeh khojandi对mvc的回复 我有最后一个解决方案,在占位符中获取字典键,并从代码中获取键的值,这不是一个好主意。 有什么提示或指南吗 课程: [ValidationProperty("Text")] public class SingleLineTe

我将sitecore 8.1与MVC一起使用,我被要求在web表单中为具有占位符文本的营销人员提供单行文本和电子邮件字段。 我已经成功创建了一个带有占位符的自定义文本字段,但有一个小问题,即它不是共享字段或不支持多文化。 我关注了@azadeh khojandi对mvc的回复

我有最后一个解决方案,在占位符中获取字典键,并从代码中获取键的值,这不是一个好主意。 有什么提示或指南吗

课程

[ValidationProperty("Text")]
public class SingleLineText : Sitecore.Form.Web.UI.Controls.SingleLineText, IPlaceholderField
{
    [VisualCategory("Custom Properties")]
    [VisualProperty("Placeholder", 2)]
    [DefaultValue("")]        
    public string PlaceHolder { get; set; }

    protected override void OnInit(EventArgs e)
    {
        // Set placeholder text, if present
        if (!string.IsNullOrEmpty(PlaceHolder))
        {
            textbox.Attributes["placeholder"] = Helper.GetDictionaryItem(PlaceHolder);
        }

        base.OnInit(e);
    }
}

public class ExtendedSingleLineTextField : Sitecore.Forms.Mvc.ViewModels.Fields.SingleLineTextField, IPlaceholderField
{
    [VisualCategory("Custom Properties")]
    [VisualProperty("Placeholder", 2)]
    [DefaultValue("")]
    public string PlaceHolder { get; set; }
}
public interface IPlaceholderField
{
    string PlaceHolder { get; set; }
}

public static class BootstrapEditorHtmlHelperExtension
{
    public static MvcHtmlString ExtendedBootstrapEditor(this HtmlHelper helper, string expression, string placeholderText, string inlineStyle, string[] classes)
    {
        var str = string.Empty;
        var viewModel = helper.ViewData.Model as IViewModel;
        if (viewModel != null)
        {
            var styleSettings = viewModel as IStyleSettings;
            if (styleSettings != null)
            {
                str = styleSettings.CssClass;
            }
            if (string.IsNullOrEmpty(placeholderText))
            {
                placeholderText = viewModel.Title;
            }
        }
        return helper.Editor(expression, new
        {
            htmlAttributes = new
            {
                @class = (string.Join(" ", classes) + " form-control" + (string.IsNullOrEmpty(str) ? string.Empty : " " + str) + (helper.ViewData.Model is SingleLineTextField ? " dangerousSymbolsCheck" : string.Empty)),
                placeholder = placeholderText,
                style = (inlineStyle ?? string.Empty)
            }
        });
    }
}
@using (Html.BeginField())
{    
    @Html.ExtendedBootstrapEditor("value", Model.PlaceHolder, "", new[] { "" })
}
自定义字段的视图

[ValidationProperty("Text")]
public class SingleLineText : Sitecore.Form.Web.UI.Controls.SingleLineText, IPlaceholderField
{
    [VisualCategory("Custom Properties")]
    [VisualProperty("Placeholder", 2)]
    [DefaultValue("")]        
    public string PlaceHolder { get; set; }

    protected override void OnInit(EventArgs e)
    {
        // Set placeholder text, if present
        if (!string.IsNullOrEmpty(PlaceHolder))
        {
            textbox.Attributes["placeholder"] = Helper.GetDictionaryItem(PlaceHolder);
        }

        base.OnInit(e);
    }
}

public class ExtendedSingleLineTextField : Sitecore.Forms.Mvc.ViewModels.Fields.SingleLineTextField, IPlaceholderField
{
    [VisualCategory("Custom Properties")]
    [VisualProperty("Placeholder", 2)]
    [DefaultValue("")]
    public string PlaceHolder { get; set; }
}
public interface IPlaceholderField
{
    string PlaceHolder { get; set; }
}

public static class BootstrapEditorHtmlHelperExtension
{
    public static MvcHtmlString ExtendedBootstrapEditor(this HtmlHelper helper, string expression, string placeholderText, string inlineStyle, string[] classes)
    {
        var str = string.Empty;
        var viewModel = helper.ViewData.Model as IViewModel;
        if (viewModel != null)
        {
            var styleSettings = viewModel as IStyleSettings;
            if (styleSettings != null)
            {
                str = styleSettings.CssClass;
            }
            if (string.IsNullOrEmpty(placeholderText))
            {
                placeholderText = viewModel.Title;
            }
        }
        return helper.Editor(expression, new
        {
            htmlAttributes = new
            {
                @class = (string.Join(" ", classes) + " form-control" + (string.IsNullOrEmpty(str) ? string.Empty : " " + str) + (helper.ViewData.Model is SingleLineTextField ? " dangerousSymbolsCheck" : string.Empty)),
                placeholder = placeholderText,
                style = (inlineStyle ?? string.Empty)
            }
        });
    }
}
@using (Html.BeginField())
{    
    @Html.ExtendedBootstrapEditor("value", Model.PlaceHolder, "", new[] { "" })
}

我已经通过在“ExtendedSingleLineTextField”和“SingleLineText”类中为占位符添加
[Localize]
属性解决了这个问题

这是在这里定义的
Sitecore.Form.Core.Attributes.LocalizeAttribute
,也用于进一步的自定义参考

第27页