mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-24 01:49:12 +08:00
Add placeholder editor form and attribute for applicable fields (#7820)
This commit is contained in:

committed by
Sébastien Ros

parent
af922a01be
commit
5ea4a7a397
@@ -16,10 +16,11 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
|
||||
protected override EditorResult OnBuildEditor(EmailField element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var placeholderEditor = BuildForm(context, "Placeholder", "Properties:10");
|
||||
var emailFieldEditor = BuildForm(context, "EmailField", "Properties:15");
|
||||
var emailFieldValidation = BuildForm(context, "EmailFieldValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, emailFieldEditor, emailFieldValidation);
|
||||
return Editor(context, autoLabelEditor, placeholderEditor, emailFieldEditor, emailFieldValidation);
|
||||
}
|
||||
|
||||
protected override void DescribeForm(DescribeContext context) {
|
||||
@@ -80,6 +81,7 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
var tokenData = context.GetTokenData();
|
||||
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
|
||||
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
context.ElementShape.ProcessedPlaceholder = _tokenizer.Replace(element.Placeholder, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
|
||||
// Allow the initial value to be tokenized.
|
||||
// If a value was posted, use that value instead (without tokenizing it).
|
||||
|
@@ -16,9 +16,10 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
|
||||
protected override EditorResult OnBuildEditor(PasswordField element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var placeholderEditor = BuildForm(context, "Placeholder", "Properties:10");
|
||||
var passwordFieldValidation = BuildForm(context, "PasswordFieldValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, passwordFieldValidation);
|
||||
return Editor(context, autoLabelEditor, placeholderEditor, passwordFieldValidation);
|
||||
}
|
||||
|
||||
protected override void DescribeForm(DescribeContext context) {
|
||||
@@ -74,8 +75,10 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
}
|
||||
|
||||
protected override void OnDisplaying(PasswordField element, ElementDisplayingContext context) {
|
||||
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
|
||||
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
var tokenData = context.GetTokenData();
|
||||
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
|
||||
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
context.ElementShape.ProcessedPlaceholder = _tokenizer.Replace(element.Placeholder, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,10 +15,11 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
|
||||
protected override EditorResult OnBuildEditor(TextArea element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var placeholderEditor = BuildForm(context, "Placeholder", "Properties:10");
|
||||
var textAreaEditor = BuildForm(context, "TextArea", "Properties:15");
|
||||
var textAreaValidation = BuildForm(context, "TextAreaValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, textAreaEditor, textAreaValidation);
|
||||
return Editor(context, autoLabelEditor, placeholderEditor, textAreaEditor, textAreaValidation);
|
||||
}
|
||||
|
||||
protected override void DescribeForm(DescribeContext context) {
|
||||
@@ -91,6 +92,7 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
var tokenData = context.GetTokenData();
|
||||
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
|
||||
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
context.ElementShape.ProcessedPlaceholder = _tokenizer.Replace(element.Placeholder, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
|
||||
// Allow the initial value to be tokenized.
|
||||
// If a value was posted, use that value instead (without tokenizing it).
|
||||
|
@@ -16,10 +16,11 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
|
||||
protected override EditorResult OnBuildEditor(TextField element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var placeholderEditor = BuildForm(context, "Placeholder", "Properties:10");
|
||||
var textFieldEditor = BuildForm(context, "TextField", "Properties:15");
|
||||
var textFieldValidation = BuildForm(context, "TextFieldValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, textFieldEditor, textFieldValidation);
|
||||
return Editor(context, autoLabelEditor, placeholderEditor, textFieldEditor, textFieldValidation);
|
||||
}
|
||||
|
||||
protected override void DescribeForm(DescribeContext context) {
|
||||
@@ -86,6 +87,7 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
var tokenData = context.GetTokenData();
|
||||
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
|
||||
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions {Encoding = ReplaceOptions.NoEncode});
|
||||
context.ElementShape.ProcessedPlaceholder = _tokenizer.Replace(element.Placeholder, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
|
||||
// Allow the initial value to be tokenized.
|
||||
// If a value was posted, use that value instead (without tokenizing it).
|
||||
|
@@ -16,10 +16,11 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
|
||||
protected override EditorResult OnBuildEditor(UrlField element, ElementEditorContext context) {
|
||||
var autoLabelEditor = BuildForm(context, "AutoLabel", "Properties:1");
|
||||
var placeholderEditor = BuildForm(context, "Placeholder", "Properties:10");
|
||||
var webAddressFieldEditor = BuildForm(context, "UrlField", "Properties:15");
|
||||
var webAddressFieldValidation = BuildForm(context, "UrlFieldValidation", "Validation:10");
|
||||
|
||||
return Editor(context, autoLabelEditor, webAddressFieldEditor, webAddressFieldValidation);
|
||||
return Editor(context, autoLabelEditor, placeholderEditor, webAddressFieldEditor, webAddressFieldValidation);
|
||||
}
|
||||
|
||||
protected override void DescribeForm(DescribeContext context) {
|
||||
@@ -74,6 +75,7 @@ namespace Orchard.DynamicForms.Drivers {
|
||||
var tokenData = context.GetTokenData();
|
||||
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
|
||||
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
context.ElementShape.ProcessedPlaceholder = _tokenizer.Replace(element.Placeholder, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
|
||||
|
||||
// Allow the initial value to be tokenized.
|
||||
// If a value was posted, use that value instead (without tokenizing it).
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using Orchard.DynamicForms.Validators.Settings;
|
||||
|
||||
namespace Orchard.DynamicForms.Elements {
|
||||
public class EmailField : LabeledFormElement {
|
||||
public class EmailField : FormElementWithPlaceholder {
|
||||
public EmailFieldValidationSettings ValidationSettings {
|
||||
get { return Data.GetModel<EmailFieldValidationSettings>(""); }
|
||||
}
|
||||
|
@@ -0,0 +1,10 @@
|
||||
using Orchard.Layouts.Helpers;
|
||||
|
||||
namespace Orchard.DynamicForms.Elements {
|
||||
public abstract class FormElementWithPlaceholder : LabeledFormElement {
|
||||
public string Placeholder {
|
||||
get { return this.Retrieve(x => x.Placeholder); }
|
||||
set { this.Store(x => x.Placeholder, value); }
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
using Orchard.DynamicForms.Validators.Settings;
|
||||
|
||||
namespace Orchard.DynamicForms.Elements {
|
||||
public class PasswordField : LabeledFormElement {
|
||||
public class PasswordField : FormElementWithPlaceholder {
|
||||
public PasswordFieldValidationSettings ValidationSettings {
|
||||
get { return Data.GetModel<PasswordFieldValidationSettings>(""); }
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
using Orchard.Layouts.Helpers;
|
||||
|
||||
namespace Orchard.DynamicForms.Elements {
|
||||
public class TextArea : LabeledFormElement {
|
||||
public class TextArea : FormElementWithPlaceholder {
|
||||
public int? Rows {
|
||||
get { return this.Retrieve(x => x.Rows); }
|
||||
set { this.Store(x => x.Rows, value); }
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using Orchard.DynamicForms.Validators.Settings;
|
||||
|
||||
namespace Orchard.DynamicForms.Elements {
|
||||
public class TextField : LabeledFormElement {
|
||||
public class TextField : FormElementWithPlaceholder {
|
||||
public TextFieldValidationSettings ValidationSettings {
|
||||
get { return Data.GetModel<TextFieldValidationSettings>(""); }
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using Orchard.DynamicForms.Validators.Settings;
|
||||
|
||||
namespace Orchard.DynamicForms.Elements {
|
||||
public class UrlField : LabeledFormElement {
|
||||
public class UrlField : FormElementWithPlaceholder {
|
||||
public UrlFieldValidationSettings ValidationSettings {
|
||||
get { return Data.GetModel<UrlFieldValidationSettings>(""); }
|
||||
}
|
||||
|
@@ -0,0 +1,22 @@
|
||||
using Orchard.Forms.Services;
|
||||
using DescribeContext = Orchard.Forms.Services.DescribeContext;
|
||||
|
||||
namespace Orchard.DynamicForms.Forms {
|
||||
public class PlaceholderForm : Component, IFormProvider {
|
||||
public void Describe(DescribeContext context) {
|
||||
context.Form("Placeholder", factory => {
|
||||
var shape = (dynamic)factory;
|
||||
var form = shape.Fieldset(
|
||||
Id: "Placeholder",
|
||||
_Placeholder: shape.Textbox(
|
||||
Id: "Placeholder",
|
||||
Name: "Placeholder",
|
||||
Title: "Placeholder",
|
||||
Classes: new[] { "text", "large", "tokenized" },
|
||||
Description: T("The text to render as placeholder.")));
|
||||
|
||||
return form;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -127,6 +127,8 @@
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Scripts\Web.config" />
|
||||
<Content Include="Styles\Web.config" />
|
||||
<Compile Include="Elements\FormElementWithPlaceholder.cs" />
|
||||
<Compile Include="Forms\PlaceholderForm.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Content Include="Module.txt" />
|
||||
</ItemGroup>
|
||||
|
@@ -8,6 +8,7 @@
|
||||
tagBuilder.Attributes["type"] = "text";
|
||||
tagBuilder.Attributes["value"] = element.Value;
|
||||
tagBuilder.Attributes["name"] = element.Name;
|
||||
tagBuilder.Attributes["placeholder"] = element.Placeholder;
|
||||
}
|
||||
|
||||
@if (element.ShowLabel) {
|
||||
|
@@ -9,6 +9,7 @@
|
||||
tagBuilder.Attributes["type"] = "email";
|
||||
tagBuilder.Attributes["value"] = Model.ProcessedValue;
|
||||
tagBuilder.Attributes["name"] = Model.ProcessedName;
|
||||
tagBuilder.Attributes["placeholder"] = Model.ProcessedPlaceholder;
|
||||
tagBuilder.AddClientValidationAttributes((IDictionary<string, string>)Model.ClientValidationAttributes);
|
||||
|
||||
if (!ViewData.ModelState.IsValidField(Model.ProcessedName)) {
|
||||
|
@@ -8,6 +8,7 @@
|
||||
tagBuilder.Attributes["type"] = "password";
|
||||
tagBuilder.Attributes["value"] = element.Value;
|
||||
tagBuilder.Attributes["name"] = element.Name;
|
||||
tagBuilder.Attributes["placeholder"] = element.Placeholder;
|
||||
}
|
||||
|
||||
@if (element.ShowLabel) {
|
||||
|
@@ -8,6 +8,7 @@
|
||||
tagBuilder.AddCssClass("text");
|
||||
tagBuilder.Attributes["type"] = "password";
|
||||
tagBuilder.Attributes["name"] = Model.ProcessedName;
|
||||
tagBuilder.Attributes["placeholder"] = Model.ProcessedPlaceholder;
|
||||
tagBuilder.AddClientValidationAttributes((IDictionary<string, string>)Model.ClientValidationAttributes);
|
||||
|
||||
if (!ViewData.ModelState.IsValidField(element.Name)) {
|
||||
|
@@ -6,6 +6,7 @@
|
||||
|
||||
tagBuilder.AddCssClass("text design");
|
||||
tagBuilder.Attributes["name"] = element.Name;
|
||||
tagBuilder.Attributes["placeholder"] = element.Placeholder;
|
||||
|
||||
if (element.Rows != null) {
|
||||
tagBuilder.Attributes["rows"] = element.Rows.ToString();
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
tagBuilder.AddCssClass("text");
|
||||
tagBuilder.Attributes["name"] = name;
|
||||
tagBuilder.Attributes["placeholder"] = Model.ProcessedPlaceholder;
|
||||
tagBuilder.AddClientValidationAttributes((IDictionary<string, string>)Model.ClientValidationAttributes);
|
||||
|
||||
if (element.Rows != null) {
|
||||
|
@@ -8,6 +8,7 @@
|
||||
tagBuilder.Attributes["type"] = "text";
|
||||
tagBuilder.Attributes["value"] = element.Value;
|
||||
tagBuilder.Attributes["name"] = element.Name;
|
||||
tagBuilder.Attributes["placeholder"] = element.Placeholder;
|
||||
}
|
||||
|
||||
@if (element.ShowLabel) {
|
||||
|
@@ -9,6 +9,7 @@
|
||||
tagBuilder.Attributes["type"] = "text";
|
||||
tagBuilder.Attributes["value"] = Model.ProcessedValue;
|
||||
tagBuilder.Attributes["name"] = Model.ProcessedName;
|
||||
tagBuilder.Attributes["placeholder"] = Model.ProcessedPlaceholder;
|
||||
tagBuilder.AddClientValidationAttributes((IDictionary<string, string>)Model.ClientValidationAttributes);
|
||||
|
||||
if (!ViewData.ModelState.IsValidField(Model.ProcessedName)) {
|
||||
|
@@ -8,6 +8,7 @@
|
||||
tagBuilder.Attributes["type"] = "url";
|
||||
tagBuilder.Attributes["value"] = element.Value;
|
||||
tagBuilder.Attributes["name"] = element.Name;
|
||||
tagBuilder.Attributes["placeholder"] = element.Placeholder;
|
||||
}
|
||||
|
||||
@if (element.ShowLabel) {
|
||||
|
@@ -9,6 +9,7 @@
|
||||
tagBuilder.Attributes["type"] = "url";
|
||||
tagBuilder.Attributes["value"] = Model.ProcessedValue;
|
||||
tagBuilder.Attributes["name"] = Model.ProcessedName;
|
||||
tagBuilder.Attributes["placeholder"] = Model.ProcessedPlaceholder;
|
||||
tagBuilder.AddClientValidationAttributes((IDictionary<string, string>)Model.ClientValidationAttributes);
|
||||
|
||||
if (!ViewData.ModelState.IsValidField(Model.ProcessedName)) {
|
||||
|
Reference in New Issue
Block a user