Skip to content

Commit

Permalink
Merge pull request #87 from cuzzlor/Issue-#79-IFieldConfiguration.Add…
Browse files Browse the repository at this point in the history
…FieldContainerClass

Issue #79 IFieldConfiguration.AddFieldContainerClass
  • Loading branch information
robdmoore committed May 10, 2014
2 parents c67708b + 1de240b commit be62bc4
Show file tree
Hide file tree
Showing 10 changed files with 487 additions and 304 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
 <dt>labelhtml</dt>
<dd class="a-container-class-1 a-container-class-2">
elementhtml validationhtml
</dd>
10 changes: 10 additions & 0 deletions ChameleonForms.Tests/Templates/Default/DefaultFormTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ public void Output_field()
HtmlApprovals.VerifyHtml(result.ToHtmlString());
}

[Test]
public void Output_field_with_container_class()
{
var t = new DefaultFormTemplate();

var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), null, new FieldConfiguration().AddFieldContainerClass("a-container-class-1").AddFieldContainerClass("a-container-class-2").ToReadonly(), false);

HtmlApprovals.VerifyHtml(result.ToHtmlString());
}

[Test]
public void Output_field_with_hint()
{
Expand Down
10 changes: 10 additions & 0 deletions ChameleonForms.Tests/Templates/TwitterBootstrap3/FieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public void Output_field()
HtmlApprovals.VerifyHtml(result.ToHtmlString());
}

[Test]
public void Output_field_with_container_class()
{
var t = new TwitterBootstrapFormTemplate();

var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), null, new FieldConfiguration().AddFieldContainerClass("a-container-class-1").AddFieldContainerClass("a-container-class-2").ToReadonly(), false);

HtmlApprovals.VerifyHtml(result.ToHtmlString());
}

[Test]
public void Output_field_with_hint()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="form-group has-error a-container-class-1 a-container-class-2">
labelhtml elementhtml
validationhtml
</div>
22 changes: 22 additions & 0 deletions ChameleonForms/Component/Config/FieldConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ public interface IFieldConfiguration : IHtmlString
/// </summary>
string LabelClasses { get; }

/// <summary>
/// Specify one or more CSS classes to use for the field container element.
/// </summary>
/// <param name="class">Any CSS class(es) to use for the field container element</param>
/// <returns>The <see cref="IFieldConfiguration"/> to allow for method chaining</returns>
IFieldConfiguration AddFieldContainerClass(string @class);

/// <summary>
/// Any CSS class(es) to use for the field container element.
/// </summary>
string FieldContainerClasses { get; }

/// <summary>
/// Specify one or more CSS classes to use for the field validation message.
/// </summary>
Expand Down Expand Up @@ -626,6 +638,16 @@ public IFieldConfiguration AddLabelClass(string @class)

public string LabelClasses { get; private set; }

public IFieldConfiguration AddFieldContainerClass(string @class)
{
if (!string.IsNullOrEmpty(FieldContainerClasses))
FieldContainerClasses += " ";
FieldContainerClasses += @class;
return this;
}

public string FieldContainerClasses { get; private set; }

public IFieldConfiguration AddValidationClass(string @class)
{
if (!string.IsNullOrEmpty(ValidationClasses))
Expand Down
10 changes: 10 additions & 0 deletions ChameleonForms/Component/Config/ReadonlyFieldConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public interface IReadonlyFieldConfiguration
/// </summary>
string LabelClasses { get; }

/// <summary>
/// Any CSS class(es) to use for the field container element.
/// </summary>
string FieldContainerClasses { get; }

/// <summary>
/// Any CSS class(es) to use for the field validation message.
/// </summary>
Expand Down Expand Up @@ -205,6 +210,11 @@ public string LabelClasses
get { return _fieldConfiguration.LabelClasses; }
}

public string FieldContainerClasses
{
get { return _fieldConfiguration.FieldContainerClasses; }
}

public string ValidationClasses
{
get { return _fieldConfiguration.ValidationClasses; }
Expand Down
12 changes: 8 additions & 4 deletions ChameleonForms/Templates/Default/DefaultHtmlHelpers.cshtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
@using System.Web.Mvc
@* Generator: MvcHelper *@
@using System.Web.Mvc
@using Component.Config
@using Enums

@* Generator: MvcHelper *@

@* The @:'s are to stop compilation errors with the Razor engine due to unclosed HTML tags *@

@helper EndForm() {
Expand Down Expand Up @@ -61,7 +60,7 @@

@helper BeginFieldInternal(IHtmlString labelHtml, IHtmlString elementHtml, IHtmlString validationHtml, IReadonlyFieldConfiguration fieldConfiguration, ModelMetadata fieldMetadata, IHtmlString requiredDesignator) {
@: <dt>@labelHtml@(new HtmlString(fieldMetadata != null && fieldMetadata.IsRequired ? requiredDesignator.ToHtmlString() : ""))</dt>
@: <dd>
@: <dd@(RenderIfNotEmpty(fieldConfiguration.FieldContainerClasses,@<text> class="@fieldConfiguration.FieldContainerClasses"</text>))>
@: @GetPrependedHtml(fieldConfiguration)@elementHtml@GetAppendedHtml(fieldConfiguration)@GetHint(fieldConfiguration) @validationHtml
}

Expand Down Expand Up @@ -118,4 +117,9 @@ foreach(var i in items) {
@: <li>@i</li>
}
@: </ul>
}

@* http://stackoverflow.com/questions/15160654/mvc-razor-helper-method-to-render-alternate-content-when-empty *@
@helper RenderIfNotEmpty(string mayBeEmpty, Func<object, IHtmlString> template) {
if (!string.IsNullOrEmpty(mayBeEmpty)) {@template(null)}
}
Loading

2 comments on commit be62bc4

@MRCollectiveCI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity ChameleonForms :: Continuous Integration Build 173 is now running

@MRCollectiveCI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity ChameleonForms :: Continuous Integration Build 1.0.5+006 outcome was SUCCESS
Summary: Tests passed: 438 Build time: 0:0:0

Please sign in to comment.