Skip to content

Commit

Permalink
Add placeholder editor form and attribute for applicable fields (Orch…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdameer authored and sebastienros committed Aug 31, 2017
1 parent af922a0 commit 5ea4a7a
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public EmailFieldElementDriver(IFormsBasedElementServices formsServices, ITokeni

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) {
Expand Down Expand Up @@ -80,6 +81,7 @@ protected override void OnDisplaying(EmailField element, ElementDisplayingContex
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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public PasswordFieldElementDriver(IFormsBasedElementServices formsServices, ITok

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) {
Expand Down Expand Up @@ -74,8 +75,10 @@ protected override void DescribeForm(DescribeContext context) {
}

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 });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public TextAreaElementDriver(IFormsBasedElementServices formsServices, ITokenize

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) {
Expand Down Expand Up @@ -91,6 +92,7 @@ protected override void OnDisplaying(TextArea element, ElementDisplayingContext
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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public TextFieldElementDriver(IFormsBasedElementServices formsServices, ITokeniz

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) {
Expand Down Expand Up @@ -86,6 +87,7 @@ protected override void OnDisplaying(TextField element, ElementDisplayingContext
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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public UrlFieldElementDriver(IFormsBasedElementServices formsServices, ITokenize

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) {
Expand Down Expand Up @@ -74,6 +75,7 @@ protected override void OnDisplaying(UrlField element, ElementDisplayingContext
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).
Expand Down
Original file line number Diff line number Diff line change
@@ -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>(""); }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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); }
}
}
}
Original file line number Diff line number Diff line change
@@ -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>(""); }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
Original file line number Diff line number Diff line change
@@ -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>(""); }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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>(""); }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 5ea4a7a

Please sign in to comment.