2016-04-20 9 views
1

MVCでsitecore 8.1を使用しています.1行のテキストが必要です&プレースホルダテキストのマーケティング担当者用のWebフォームの電子メールフィールド。 プレースホルダでカスタムテキストフィールドを作成しましたが、共有フィールドでもマルチカルチャでもないという小さな問題があります。 mvcの@ azadeh-khojandiの返信に従っていますhereマーケティング担当者のカスタムフィールド属性のためのsitecore Webフォームの共有フィールド

私は、プレースホルダーとコード取得キーの値を良いアイデアではないと考えている最後の解決方法があります。 ヒントやガイドはありますか?

クラス:カスタムフィールドため

[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[] { "" }) 
} 

答えて

関連する問題