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

Add InputTagHelper #1359

Merged
merged 1 commit into from
Oct 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/TagHelperSample.Web/Views/Home/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div class="col-md-10">
@* will automatically infer type="date" (reused HTML attribute) and format="{0:d}" (optional bound attribute) *@
<input for="DateOfBirth" />
<span validation-for="DateOfBirth">How old are you?</span>
<span validation-for="DateOfBirth">When were you born?</span>
</div>
</div>
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion samples/TagHelperSample.Web/Views/Home/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<label for="DateOfBirth" class="control-label col-md-2" />
<div class="col-md-10">
<input type="date" for="DateOfBirth" format="{0:d}" />
<span validation-for="DateOfBirth">How old are you?</span>
<span validation-for="DateOfBirth" />
</div>
</div>
<div class="form-group">
Expand Down
415 changes: 415 additions & 0 deletions src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions src/Microsoft.AspNet.Mvc.TagHelpers/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,27 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AnchorTagHelper_CannotDetermineHrefRouteActionOrControllerSpecified" xml:space="preserve">
<value>Cannot determine an {4} for {0}. An {0} with a specified {1} must not have an {2} or {3} attribute.</value>
<value>Cannot determine an '{4}' for {0}. An {0} with a specified '{1}' must not have an '{2}' or '{3}' attribute.</value>
</data>
<data name="AnchorTagHelper_CannotOverrideSpecifiedHref" xml:space="preserve">
<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>
<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>
</data>
<data name="InputTagHelper_InvalidExpressionResult" xml:space="preserve">
<value>Unexpected '{1}' expression result type '{2}' for {0}. '{1}' must be of type '{3}' if '{4}' is '{5}'.</value>
</data>
<data name="InputTagHelper_UnableToFormat" xml:space="preserve">
<value>Unable to format without a '{1}' expression for {0}. '{2}' must be null if '{1}' is null.</value>
</data>
<data name="InputTagHelper_ValueRequired" xml:space="preserve">
<value>'{1}' must not be null for {0} if '{2}' is '{3}'.</value>
</data>
<data name="FormTagHelper_CannotDetermineAction" xml:space="preserve">
<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>
<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>
</data>
<data name="ValidationSummaryTagHelper_InvalidValidationSummaryValue" xml:space="preserve">
<value>Cannot parse '{1}' value '{2}' for {0}. Acceptable values are '{3}', '{4}' and '{5}'.</value>
</data>
<data name="TagHelpers_NoProvidedMetadata" xml:space="preserve">
<value>The {2} was unable to provide metadata about '{1}' expression value '{3}' for {0}.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public static void MergeAttributes(this TagHelperOutput tagHelperOutput, TagBuil
{
foreach (var attribute in tagBuilder.Attributes)
{
if (!tagHelperOutput.Attributes.ContainsKey(attribute.Key))
// TODO: Use Attributes.ContainsKey once aspnet/Razor#186 is fixed.
if (!tagHelperOutput.Attributes.Any(
item => string.Equals(attribute.Key, item.Key, StringComparison.OrdinalIgnoreCase)))
{
tagHelperOutput.Attributes.Add(attribute.Key, attribute.Value);
}
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.AspNet.Mvc.TagHelpers/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"warningsAsErrors": true
},
"dependencies": {
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
"Microsoft.AspNet.Mvc.Razor": ""
},
"frameworks": {
Expand Down
10 changes: 5 additions & 5 deletions test/Microsoft.AspNet.Mvc.TagHelpers.Test/AnchorTagHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ public async Task ProcessAsync_ThrowsIfHrefConflictsWithBoundAttributes(string p
typeof(AnchorTagHelper).GetProperty(propertyName).SetValue(anchorTagHelper, "Home");
}

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

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

// Act & Assert
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ public async Task ProcessAsync_ThrowsIfActionIsUrlWithSpecifiedController()
Controller = "Home",
Method = "POST"
};
var expectedErrorMessage = "Cannot determine an action for <form>. A <form> with a URL-based action " +
"must not have attributes starting with route- or a controller attribute.";
var expectedErrorMessage = "Cannot determine an 'action' for <form>. A <form> with a URL-based 'action' " +
"must not have attributes starting with 'route-' or a 'controller' attribute.";
var tagHelperOutput = new TagHelperOutput(
"form",
attributes: new Dictionary<string, string>(),
Expand All @@ -324,8 +324,8 @@ public async Task ProcessAsync_ThrowsIfActionIsUrlWithSpecifiedRoutes()
Action = "http://www.contoso.com",
Method = "POST"
};
var expectedErrorMessage = "Cannot determine an action for <form>. A <form> with a URL-based action " +
"must not have attributes starting with route- or a controller attribute.";
var expectedErrorMessage = "Cannot determine an 'action' for <form>. A <form> with a URL-based 'action' " +
"must not have attributes starting with 'route-' or a 'controller' attribute.";
var tagHelperOutput = new TagHelperOutput(
"form",
attributes: new Dictionary<string, string>
Expand Down
Loading