2016-04-20 66 views
1

我正在使用帶有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[] { "" }) 
} 

回答

相關問題