Add placeholder editor form and attribute for applicable fields (#7820)

This commit is contained in:
Mohammad Dameer
2017-08-31 22:18:45 +03:00
committed by Sébastien Ros
parent af922a01be
commit 5ea4a7a397
23 changed files with 67 additions and 12 deletions

View File

@@ -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).

View File

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

View File

@@ -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).

View File

@@ -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).

View File

@@ -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).

View File

@@ -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>(""); }
}

View File

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

View File

@@ -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>(""); }
}

View File

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

View File

@@ -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>(""); }
}

View File

@@ -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>(""); }
}

View File

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

View File

@@ -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>

View File

@@ -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) {

View File

@@ -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)) {

View File

@@ -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) {

View File

@@ -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)) {

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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)) {

View File

@@ -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) {

View File

@@ -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)) {