Suppress validation summary `<div>` when nothing is generated
- #2372 - make the `ValidationSummaryTagHelper` behave consistently with `Html.ValidationSummar()`
This commit is contained in:
parent
6cdd0451da
commit
0a4c06eefb
|
|
@ -104,11 +104,15 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
message: null,
|
message: null,
|
||||||
headerTag: null,
|
headerTag: null,
|
||||||
htmlAttributes: null);
|
htmlAttributes: null);
|
||||||
if (tagBuilder != null)
|
if (tagBuilder == null)
|
||||||
{
|
{
|
||||||
output.MergeAttributes(tagBuilder);
|
// The generator determined no element was necessary.
|
||||||
output.PostContent.AppendHtml(tagBuilder.InnerHtml);
|
output.SuppressOutput();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output.MergeAttributes(tagBuilder);
|
||||||
|
output.PostContent.AppendHtml(tagBuilder.InnerHtml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
<div class="order validation-summary-errors" data-valmsg-summary="true"><ul><li>The value '' is invalid.</li>
|
<div class="order validation-summary-errors" data-valmsg-summary="true"><ul><li>The value '' is invalid.</li>
|
||||||
<li>The Password field is required.</li>
|
<li>The Password field is required.</li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
<div class="order"></div>
|
|
||||||
<input type="submit"/>
|
<input type="submit"/>
|
||||||
<input name="__RequestVerificationToken" type="hidden" value="{0}" /></form>
|
<input name="__RequestVerificationToken" type="hidden" value="{0}" /></form>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="order validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li>
|
<div class="order validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
<div class="order"></div>
|
|
||||||
<input type="submit"/>
|
<input type="submit"/>
|
||||||
<input name="__RequestVerificationToken" type="hidden" value="{0}" /></form>
|
<input name="__RequestVerificationToken" type="hidden" value="{0}" /></form>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||||
|
|
@ -96,7 +97,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(ProcessAsync_GeneratesExpectedOutput_WithNoErrorsData))]
|
[MemberData(nameof(ProcessAsync_GeneratesExpectedOutput_WithNoErrorsData))]
|
||||||
public async Task ProcessAsync_DoesNothingIfClientSideValiationDisabled_WithNoErrorsData(
|
public async Task ProcessAsync_SuppressesOutput_IfClientSideValiationDisabled_WithNoErrorsData(
|
||||||
ModelStateDictionary modelStateDictionary)
|
ModelStateDictionary modelStateDictionary)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -128,16 +129,12 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
await validationSummaryTagHelper.ProcessAsync(context, output);
|
await validationSummaryTagHelper.ProcessAsync(context, output);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("div", output.TagName);
|
Assert.Null(output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
Assert.False(output.IsContentModified);
|
Assert.Empty(HtmlContentUtilities.HtmlContentToString(output));
|
||||||
Assert.False(output.PreContent.IsModified);
|
|
||||||
Assert.False(output.PreElement.IsModified);
|
|
||||||
Assert.False(output.PostContent.IsModified);
|
|
||||||
Assert.False(output.PostElement.IsModified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TheoryData<string, ModelStateDictionary> ProcessAsync_DoesNothingIfModelOnly_WithNoModelErrorData
|
public static TheoryData<string, ModelStateDictionary> ProcessAsync_SuppressesOutput_IfModelOnlyWithNoModelErrorData
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
@ -165,8 +162,8 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData(nameof(ProcessAsync_DoesNothingIfModelOnly_WithNoModelErrorData))]
|
[MemberData(nameof(ProcessAsync_SuppressesOutput_IfModelOnlyWithNoModelErrorData))]
|
||||||
public async Task ProcessAsync_DoesNothingIfModelOnly_WithNoModelError(
|
public async Task ProcessAsync_SuppressesOutput_IfModelOnly_WithNoModelError(
|
||||||
string prefix,
|
string prefix,
|
||||||
ModelStateDictionary modelStateDictionary)
|
ModelStateDictionary modelStateDictionary)
|
||||||
{
|
{
|
||||||
|
|
@ -199,13 +196,9 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
await validationSummaryTagHelper.ProcessAsync(context, output);
|
await validationSummaryTagHelper.ProcessAsync(context, output);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("div", output.TagName);
|
Assert.Null(output.TagName);
|
||||||
Assert.Empty(output.Attributes);
|
Assert.Empty(output.Attributes);
|
||||||
Assert.False(output.IsContentModified);
|
Assert.Empty(HtmlContentUtilities.HtmlContentToString(output));
|
||||||
Assert.False(output.PreContent.IsModified);
|
|
||||||
Assert.False(output.PreElement.IsModified);
|
|
||||||
Assert.False(output.PostContent.IsModified);
|
|
||||||
Assert.False(output.PostElement.IsModified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue