gpt4 book ai didi

sitecore - 营销人员 Web 表单 (WFFM) 具有占位符属性的 Html 输入标记

转载 作者:行者123 更新时间:2023-12-01 17:32:02 27 4
gpt4 key购买 nike

我有一个要求,要实现 sitecore WFFM 来创建表单。该页面具有带有 Placeholder 属性的 HTML 输入标记。我必须将 WFFM SingleLineInput 框渲染到具有占位符属性的输入标记。我该怎么办?

我知道 SingleLineText 类是在 Sitecore.Form.Web.UI.Controls dll 中定义的。

最佳答案

如果您使用的是 WFFM 的 MVC 版本,您需要按照批准的答案中的说明添加以下内容

1-创建一个类

 public interface IPlaceholderField
{
string PlaceHolder { get; set; }
}

[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"] = 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; }

}

2- 将单行文本从 /sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types/Simple Types/Single-Line Text 复制到 /sitecore/system/模块/营销人员网络表单/设置/字段类型/自定义 设置程序集、类和 MVC 类型

enter image description here

3-在\Views\Form\EditorTemplates 下创建一个新的 chtml 文件,并将其命名为 ExtendedSingleLineTextField.cshtml,它应该与类名相同(ExtendedSingleLineTextField)

@using Sitecore.Forms.Mvc.Html
@using LendLease.Web.HtmlHelpers
@model LendLease.Extension.Sc.WFFM.ExtendedSingleLineTextField


@using (Html.BeginField())
{
@*@Html.TextBoxFor(m => m.Value, new { placeholder = Model.PlaceHolder })*@
@Html.ExtendedBootstrapEditor("value",Model.PlaceHolder,"",new []{""})

}

添加一个 html 帮助器,以便您可以注入(inject)占位符,我将其命名为 BootstrapEditorHtmlHelperExtension.cs

  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)
}
});
}
}

关于sitecore - 营销人员 Web 表单 (WFFM) 具有占位符属性的 Html 输入标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25718911/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com