Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 012e03e

Browse files
committed
Add InputTagHelper
- also make `TagHelperOutputExtensions.MergeAttributes()` case-insensitive nits: - deliniate attribute names in all resource strings - update validation messages in TagHelperSample.Web
1 parent f8f08f0 commit 012e03e

File tree

10 files changed

+715
-21
lines changed

10 files changed

+715
-21
lines changed

samples/TagHelperSample.Web/Views/Home/Create.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<div class="col-md-10">
3838
@* will automatically infer type="date" (reused HTML attribute) and format="{0:d}" (optional bound attribute) *@
3939
<input for="DateOfBirth" />
40-
<span validation-for="DateOfBirth">How old are you?</span>
40+
<span validation-for="DateOfBirth">When were you born?</span>
4141
</div>
4242
</div>
4343
<div class="form-group">

samples/TagHelperSample.Web/Views/Home/Edit.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<label for="DateOfBirth" class="control-label col-md-2" />
2121
<div class="col-md-10">
2222
<input type="date" for="DateOfBirth" format="{0:d}" />
23-
<span validation-for="DateOfBirth">How old are you?</span>
23+
<span validation-for="DateOfBirth" />
2424
</div>
2525
</div>
2626
<div class="form-group">

src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs

Lines changed: 415 additions & 0 deletions
Large diffs are not rendered by default.

src/Microsoft.AspNet.Mvc.TagHelpers/Properties/Resources.Designer.cs

Lines changed: 70 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.AspNet.Mvc.TagHelpers/Resources.resx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,27 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<data name="AnchorTagHelper_CannotDetermineHrefRouteActionOrControllerSpecified" xml:space="preserve">
121-
<value>Cannot determine an {4} for {0}. An {0} with a specified {1} must not have an {2} or {3} attribute.</value>
121+
<value>Cannot determine an '{4}' for {0}. An {0} with a specified '{1}' must not have an '{2}' or '{3}' attribute.</value>
122122
</data>
123123
<data name="AnchorTagHelper_CannotOverrideSpecifiedHref" xml:space="preserve">
124-
<value>Cannot determine an {8} for {0}. An {0} with a specified {8} must not have attributes starting with {7} or an {1}, {2}, {3}, {4}, {5} or {6} attribute.</value>
124+
<value>Cannot determine an '{8}' for {0}. An {0} with a specified '{8}' must not have attributes starting with '{7}' or an '{1}', '{2}', '{3}', '{4}', '{5}', or '{6}' attribute.</value>
125+
</data>
126+
<data name="InputTagHelper_InvalidExpressionResult" xml:space="preserve">
127+
<value>Unexpected '{1}' expression result type '{2}' for {0}. '{1}' must be of type '{3}' if '{4}' is '{5}'.</value>
128+
</data>
129+
<data name="InputTagHelper_UnableToFormat" xml:space="preserve">
130+
<value>Unable to format without a '{1}' expression for {0}. '{2}' must be null if '{1}' is null.</value>
131+
</data>
132+
<data name="InputTagHelper_ValueRequired" xml:space="preserve">
133+
<value>'{1}' must not be null for {0} if '{2}' is '{3}'.</value>
125134
</data>
126135
<data name="FormTagHelper_CannotDetermineAction" xml:space="preserve">
127-
<value>Cannot determine an {1} for {0}. A {0} with a URL-based {1} must not have attributes starting with {3} or a {2} attribute.</value>
136+
<value>Cannot determine an '{1}' for {0}. A {0} with a URL-based '{1}' must not have attributes starting with '{3}' or a '{2}' attribute.</value>
128137
</data>
129138
<data name="ValidationSummaryTagHelper_InvalidValidationSummaryValue" xml:space="preserve">
130139
<value>Cannot parse '{1}' value '{2}' for {0}. Acceptable values are '{3}', '{4}' and '{5}'.</value>
131140
</data>
141+
<data name="TagHelpers_NoProvidedMetadata" xml:space="preserve">
142+
<value>The {2} was unable to provide metadata about '{1}' expression value '{3}' for {0}.</value>
143+
</data>
132144
</root>

src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperOutputExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public static void MergeAttributes(this TagHelperOutput tagHelperOutput, TagBuil
8989
{
9090
foreach (var attribute in tagBuilder.Attributes)
9191
{
92-
if (!tagHelperOutput.Attributes.ContainsKey(attribute.Key))
92+
// TODO: Use Attributes.ContainsKey once aspnet/Razor#186 is fixed.
93+
if (!tagHelperOutput.Attributes.Any(
94+
item => string.Equals(attribute.Key, item.Key, StringComparison.OrdinalIgnoreCase)))
9395
{
9496
tagHelperOutput.Attributes.Add(attribute.Key, attribute.Value);
9597
}

src/Microsoft.AspNet.Mvc.TagHelpers/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"warningsAsErrors": true
55
},
66
"dependencies": {
7+
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
78
"Microsoft.AspNet.Mvc.Razor": ""
89
},
910
"frameworks": {

test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ public async Task ProcessAsync_ThrowsIfHrefConflictsWithBoundAttributes(string p
176176
typeof(AnchorTagHelper).GetProperty(propertyName).SetValue(anchorTagHelper, "Home");
177177
}
178178

179-
var expectedErrorMessage = "Cannot determine an href for <a>. An <a> with a specified href must not " +
180-
"have attributes starting with route- or an action, controller, route, " +
181-
"protocol, host or fragment attribute.";
179+
var expectedErrorMessage = "Cannot determine an 'href' for <a>. An <a> with a specified 'href' must not " +
180+
"have attributes starting with 'route-' or an 'action', 'controller', " +
181+
"'route', 'protocol', 'host', or 'fragment' attribute.";
182182

183183
// Act & Assert
184184
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
@@ -202,8 +202,8 @@ public async Task ProcessAsync_ThrowsIfRouteAndActionOrControllerProvided(string
202202
"a",
203203
attributes: new Dictionary<string, string>(),
204204
content: string.Empty);
205-
var expectedErrorMessage = "Cannot determine an href for <a>. An <a> with a " +
206-
"specified route must not have an action or controller attribute.";
205+
var expectedErrorMessage = "Cannot determine an 'href' for <a>. An <a> with a " +
206+
"specified 'route' must not have an 'action' or 'controller' attribute.";
207207

208208
// Act & Assert
209209
var ex = await Assert.ThrowsAsync<InvalidOperationException>(

test/Microsoft.AspNet.Mvc.TagHelpers.Test/FormTagHelperTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ public async Task ProcessAsync_ThrowsIfActionIsUrlWithSpecifiedController()
301301
Controller = "Home",
302302
Method = "POST"
303303
};
304-
var expectedErrorMessage = "Cannot determine an action for <form>. A <form> with a URL-based action " +
305-
"must not have attributes starting with route- or a controller attribute.";
304+
var expectedErrorMessage = "Cannot determine an 'action' for <form>. A <form> with a URL-based 'action' " +
305+
"must not have attributes starting with 'route-' or a 'controller' attribute.";
306306
var tagHelperOutput = new TagHelperOutput(
307307
"form",
308308
attributes: new Dictionary<string, string>(),
@@ -324,8 +324,8 @@ public async Task ProcessAsync_ThrowsIfActionIsUrlWithSpecifiedRoutes()
324324
Action = "http://www.contoso.com",
325325
Method = "POST"
326326
};
327-
var expectedErrorMessage = "Cannot determine an action for <form>. A <form> with a URL-based action " +
328-
"must not have attributes starting with route- or a controller attribute.";
327+
var expectedErrorMessage = "Cannot determine an 'action' for <form>. A <form> with a URL-based 'action' " +
328+
"must not have attributes starting with 'route-' or a 'controller' attribute.";
329329
var tagHelperOutput = new TagHelperOutput(
330330
"form",
331331
attributes: new Dictionary<string, string>

0 commit comments

Comments
 (0)