-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Closed
Copy link
Labels
area-ui-renderingIncludes: MVC Views/Pages, Razor Views/PagesIncludes: MVC Views/Pages, Razor Views/PagesbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.good first issueGood for newcomers.Good for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issueUp for grabs. We would accept a PR to help resolve this issue
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I have the following code:
<label form="document-generator-single-form" asp-for="DeadlineToResubmissionDate" class="form-label"></label>
<input form="document-generator-single-form" asp-for="DeadlineToResubmissionDate" type="checkbox" class="form-check"/>
<span form="document-generator-single-form" asp-validation-for="DeadlineToResubmissionDate" class="invalid-feedback"></span>
This code generates a hidden field, which i suppose should represent the payload for this input field when it's not selected:
<input name="DeadlineToResubmissionDate" type="hidden" value="false">
However the form attribute, which should point to the id of the submission form is missing here.
I also conducted the Request-Payload and the DeadlineToResubmissionDate property is missing from the request completely.
Expected Behavior
Either the hidden input should respect the given form from the Tag-Helper, or something is happening inside here, I am missing:
aspnetcore/src/Mvc/Mvc.TagHelpers/src/InputTagHelper.cs
Lines 317 to 338 in 53aad98
if (hiddenForCheckboxTag != null) | |
{ | |
var renderingMode = | |
output.TagMode == TagMode.SelfClosing ? TagRenderMode.SelfClosing : TagRenderMode.StartTag; | |
hiddenForCheckboxTag.TagRenderMode = renderingMode; | |
if (!hiddenForCheckboxTag.Attributes.ContainsKey("name") && | |
!string.IsNullOrEmpty(Name)) | |
{ | |
// The checkbox and hidden elements should have the same name attribute value. Attributes will | |
// match if both are present because both have a generated value. Reach here in the special case | |
// where user provided a non-empty fallback name. | |
hiddenForCheckboxTag.MergeAttribute("name", Name); | |
} | |
if (ViewContext.CheckBoxHiddenInputRenderMode == CheckBoxHiddenInputRenderMode.EndOfForm && ViewContext.FormContext.CanRenderAtEndOfForm) | |
{ | |
ViewContext.FormContext.EndOfFormContent.Add(hiddenForCheckboxTag); | |
} | |
else | |
{ | |
output.PostElement.AppendHtml(hiddenForCheckboxTag); | |
} |
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
6.0.411
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area-ui-renderingIncludes: MVC Views/Pages, Razor Views/PagesIncludes: MVC Views/Pages, Razor Views/PagesbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.good first issueGood for newcomers.Good for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issueUp for grabs. We would accept a PR to help resolve this issue