Skip to content

Checkbox Tag-Helper ignores form attribute when hidden input is generated #49201

@m0ddixx

Description

@m0ddixx

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:

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

No one assigned

    Labels

    area-ui-renderingIncludes: MVC Views/Pages, Razor Views/PagesbugThis issue describes a behavior which is not expected - a bug.good first issueGood for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions