sitecore的共享字段营销人员的Web表单自定义字段属性
问题描述:
我正在使用带有MVC的sitecore 8.1,并且我需要单行文本&带有占位符文本的营销人员的Web表单中的电子邮件字段。 我用占位符成功创建了一个自定义文本字段,但有一个小问题,它不是共享字段或多文化支持。 我遵循了MVC heresitecore的共享字段营销人员的Web表单自定义字段属性
@ azadeh-khojandi回复我有一个最后的解决方案采取占位符,并从代码获取键的值的字典键这不应该是一个不错的主意。 任何提示或指导?
类:
[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” 添加占位符[Localize]
属性解决这个问题,“SingleLineText“类。
这在这里定义为Sitecore.Form.Core.Attributes.LocalizeAttribute
并且还用于进一步定制参考。