Skip to content

Commit 5b11999

Browse files
committed
Reviewed PR and fixed a bunch of stuff:
* Added back default cols="20" rows="2" for <textarea>'s * Added overloads for templated razor delegates for all relevant IHtmlContent arguments * Deleted superfluous AssemblyInfo.cs and packages.config and app.config and twitterbootstrap3.nuspec files * Uncommented commented out test * Fixed up changed required metadata on twitter bootstrap tests * Set master branch as beta in gitversion so we can release to github after merging the PR
1 parent 456bdd0 commit 5b11999

20 files changed

+59
-388
lines changed

ChameleonForms.AcceptanceTests/IntegrationTests/PartialForTests.Should_render_correctly_when_used_via_form_or_section_and_when_used_for_top_level_property_or_sub_property.approved.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ <h1>Partials</h1>
161161

162162
<dt><label for="TextAreaField">Text area field</label></dt>
163163
<dd>
164-
<textarea id="TextAreaField" name="TextAreaField">Initial value</textarea>from partial against top-level model <span class="field-validation-valid" data-valmsg-for="TextAreaField" data-valmsg-replace="true"></span>
164+
<textarea cols="20" id="TextAreaField" name="TextAreaField" rows="2">Initial value</textarea>from partial against top-level model <span class="field-validation-valid" data-valmsg-for="TextAreaField" data-valmsg-replace="true"></span>
165165
</dd>
166166

167167

ChameleonForms.Example/Views/ExampleForms/Form1.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{
1818
<p>@f.LabelFor(m => m.SomeCheckbox).Label("Are you ready for: ") @f.FieldElementFor(m => m.SomeCheckbox) @f.ValidationMessageFor(m => m.SomeCheckbox)</p>
1919
<p>@f.FieldElementFor(m => m.RequiredStringField).TabIndex(4)</p>
20-
using (var s = f.BeginSection("My Section!", InstructionalText(null), new { @class = "aClass" }.ToHtmlAttributes()))
20+
using (var s = f.BeginSection("My Section!", InstructionalText, new { @class = "aClass" }.ToHtmlAttributes()))
2121
{
2222
@s.FieldFor(m => m.FlagsEnums)
2323
@s.FieldFor(m => m.Boolean).WithoutInlineLabel()

ChameleonForms.Generated/Properties/AssemblyInfo.cs

-36
This file was deleted.

ChameleonForms.Tests/Component/MessageTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ public void Construct_section_via_extension_method_without_heading([ValueSource(
6666
_f.Received().Write(_beginHtml);
6767
}
6868

69-
//[Test]
70-
//public void Create_a_paragraph_with_a_string()
71-
//{
72-
// var html = Substitute.For<IHtmlContent>();
73-
// var s = Arrange(MessageType.Success);
74-
// _f.Template.MessageParagraph(Arg.Is<IHtmlContent>(h => h.ToHtmlString() == "aerg&amp;%^&quot;esrg&#39;"))
75-
// .Returns(html);
76-
77-
// var paragraph = s.Paragraph("aerg&%^\"esrg'");
78-
79-
// Assert.That(paragraph, Is.EqualTo(html));
80-
//}
69+
[Test]
70+
public void Create_a_paragraph_with_a_string()
71+
{
72+
var html = Substitute.For<IHtmlContent>();
73+
var s = Arrange(MessageType.Success);
74+
_f.Template.MessageParagraph(Arg.Is<IHtmlContent>(h => h.ToHtmlString() == "aerg&amp;%^&quot;esrg&#39;"))
75+
.Returns(html);
76+
77+
var paragraph = s.Paragraph("aerg&%^\"esrg'");
78+
79+
Assert.That(paragraph, Is.EqualTo(html));
80+
}
8181

8282
[Test]
8383
public void Create_a_paragraph_with_html()
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<textarea class="input-validation-error" data-attr="value" id="Textarea" name="Textarea"></textarea>
1+
<textarea class="input-validation-error" cols="20" data-attr="value" id="Textarea" name="Textarea" rows="2"></textarea>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<textarea class="input-validation-error" cols="60" data-attr="value" id="Textarea" name="Textarea" rows="5"></textarea>

ChameleonForms.Tests/FieldGenerator/DefaultFieldGenerator/InputTests.cs

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ public void Use_correct_html_for_textarea()
5656
HtmlApprovals.VerifyHtml(result.ToHtmlString());
5757
}
5858

59+
[Test]
60+
public void Use_correct_html_for_textarea_with_overriden_cols_and_rows()
61+
{
62+
var g = Arrange(m => m.Textarea);
63+
64+
var result = g.GetFieldHtml(ExampleFieldConfiguration.Cols(60).Rows(5));
65+
66+
HtmlApprovals.VerifyHtml(result.ToHtmlString());
67+
}
68+
5969
[Test]
6070
public void Use_correct_html_for_email()
6171
{

ChameleonForms.Tests/Properties/AssemblyInfo.cs

-36
This file was deleted.

ChameleonForms.Tests/Templates/TwitterBootstrap3/FieldTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void Output_field_with_prepended_and_appended_html()
4848
{
4949
var t = new TwitterBootstrapFormTemplate();
5050

51-
var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), GetRequiredMetadata(), new FieldConfiguration()
51+
var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), null, new FieldConfiguration()
5252
.Prepend(new HtmlString("<1>")).Prepend(new HtmlString("<2>"))
5353
.Append(new HtmlString("<3>")).Append(new HtmlString("<4>"))
5454
.WithHint(new HtmlString("<hint>")),
@@ -62,7 +62,7 @@ public void Output_field_with_prepended_and_appended_html_when_input_group()
6262
{
6363
var t = new TwitterBootstrapFormTemplate();
6464

65-
var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), null, new FieldConfiguration()
65+
var result = t.Field(new HtmlString("labelhtml"), new HtmlString("elementhtml"), new HtmlString("validationhtml"), GetRequiredMetadata(), new FieldConfiguration()
6666
.Prepend(new HtmlString("<1>")).Prepend(new HtmlString("<2>"))
6767
.Append(new HtmlString("<3>")).Append(new HtmlString("<4>"))
6868
.WithHint(new HtmlString("<hint>"))
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
 <div class="form-group has-error">
2-
labelhtml<em class="required" title="Required">&lowast;</em>
3-
<2><1>elementhtml<3><4>
2+
labelhtml <2><1>elementhtml<3><4>
43
<div class="help-block form-hint"><hint></div> validationhtml
54
</div>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
 <div class="form-group has-error">
2-
labelhtml <2><1>elementhtml<3><4>
2+
labelhtml<em class="required" title="Required">&lowast;</em>
3+
<2><1>elementhtml<3><4>
34
<div class="help-block form-hint"><hint></div> validationhtml
45
</div>

ChameleonForms.Tests/packages.config

-18
This file was deleted.

ChameleonForms.TwitterBootstrap3.nuspec

-37
This file was deleted.

ChameleonForms/FieldGenerators/Handlers/TextAreaHandler.cs

+9
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,14 @@ public override FieldDisplayType GetDisplayType(IReadonlyFieldConfiguration fiel
4141
{
4242
return FieldDisplayType.MultiLineText;
4343
}
44+
45+
public override void PrepareFieldConfiguration(IFieldConfiguration fieldConfiguration)
46+
{
47+
// Ensure textareas look consistent across browsers by having default values as per MDN recommendations
48+
if (!fieldConfiguration.Attributes.Has("rows"))
49+
fieldConfiguration.Rows(2);
50+
if (!fieldConfiguration.Attributes.Has("cols"))
51+
fieldConfiguration.Cols(20);
52+
}
4453
}
4554
}

ChameleonForms/ModelBinders/FlagsEnumModelBinder.cs

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc;
2-
using Microsoft.AspNetCore.Mvc.ModelBinding;
1+
using Microsoft.AspNetCore.Mvc.ModelBinding;
32
using System;
4-
using System.Collections.Generic;
5-
using System.Globalization;
63
using System.Linq;
74
using System.Threading.Tasks;
85

@@ -32,24 +29,21 @@ public Task BindModelAsync(ModelBindingContext bindingContext)
3229
}
3330
else
3431
{
35-
bindingContext.ModelState.AddModelError(bindingContext.ModelName
36-
, string.Format("The value '{0}' is not valid for {1}."
37-
, enumValue
38-
, bindingContext.ModelMetadata.DisplayName ?? bindingContext.ModelMetadata.PropertyName
39-
));
32+
bindingContext.ModelState.AddModelError(
33+
bindingContext.ModelName,
34+
string.Format("The value '{0}' is not valid for {1}.",
35+
enumValue,
36+
bindingContext.ModelMetadata.DisplayName ?? bindingContext.ModelMetadata.PropertyName)
37+
);
4038
}
4139
}
4240

43-
if(enumValueAsLong == null)
41+
if (enumValueAsLong == null)
4442
{
45-
if(nullable)
46-
{
43+
if (nullable)
4744
bindingContext.Result = ModelBindingResult.Success(null);
48-
}
4945
else
50-
{
5146
bindingContext.Result = ModelBindingResult.Failed();
52-
}
5347
}
5448
else
5549
{

ChameleonForms/Properties/AssemblyInfo.cs

-36
This file was deleted.

ChameleonForms/ServiceCollectionExtensions.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313
namespace ChameleonForms
1414
{
1515
// todo: needed for beta release in priority order
16+
// switch datetimemodelbindershould and flagsenummodelbindershould to modelbindertestbase
1617
// doco: int/datetime client validation support, email and url fields, client side file copying, how to set up twitter bootstrap 3, view namespace getting started
1718
// test Uri binding works?
1819
// Add ability to switch unobtrusive validation on/off and html5 validation on/off (<form novalidate="novalidate">) - global default with per-form override? reference ValidationHtmlAttributeProvider in documentation
19-
// Twitter bootstrap: template, service collection extension, doco
20+
// Twitter bootstrap: template, service collection extension, doco, remove WebViewPage
2021
// Update all dependencies to latest versions
21-
// Review the datetime "g" and current culture things - remove?
22+
// Review the datetime "g" and current culture things - remove? client side validation for non / separators?
2223
// Test adding package to a fresh web project
23-
// Add public api surface area approval test, compare to old library to identify gaps, update breakingchanges file
24+
// Add public api surface area approval test, compare to old library to identify gaps, update breakingchanges file (include textarea cols and rows)
2425
// End-to-end documentation review and update - @helper, IHtmlString, web.config, update Message, Navigation etc.
2526
// todo: 4.0 non-beta release
27+
// blog posts: razorgenerator, mvctestcontext, modelbindertestbase, ilmerge, client validation in aspnetcore, end-to-end test in-memory, disposablehtmlhelper
2628
// Generate nuget from .csproj rather than nuspec like https://github.com/LazZiya/ExpressLocalization/blob/master/LazZiya.ExpressLocalization/LazZiya.ExpressLocalization.csproj
29+
// [Range] client validation support
2730
// Add support for non jquery unobtrusive validation
2831
// Add bootstrap4
2932
// Add tag helper equivalent to the raw mvc comparison example

0 commit comments

Comments
 (0)