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

InputTagHelper doesn't copy pre-existing attributes correctly for checkboxes. #5981

Closed
NTaylorMullen opened this issue Mar 17, 2017 · 1 comment
Assignees

Comments

@NTaylorMullen
Copy link
Contributor

Given the following TagHelper:

[HtmlTargetElement("input", Attributes = "asp-for,[type=checkbox]")]
public class FooTagHelper : TagHelper
{
    public override int Order => -2000;

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        var tb = new TagBuilder("input");
        tb.AddCssClass("myclass");
        output.MergeAttributes(tb);
    }
}

And the following source:

<input asp-for="BoolVal" class="my-control" type="checkbox" />

You end up getting an invalid class attribute value:

<input checked="checked" class="Microsoft.AspNetCore.Mvc.TagHelpers.TagHelperOutputExtensions&#x2B;ClassAttributeHtmlContent" data-val="true" data-val-required="The BoolVal field is required." id="BoolVal" name="BoolVal" type="checkbox" value="true" /><input name="BoolVal" type="hidden" value="false" />

This is because of how we copy the pre-existing output attributes.

@dougbu
Copy link
Member

dougbu commented Apr 5, 2017

Root cause is the HtmlGenerator does not handle IHtmlContent in htmlAttribute dictionaries it's given. No need for such support elsewhere; the MVC tag helpers should be passing htmlAttributes: null except in this one case.

This problem would mostly go away if we fixed #5902. But, might still need to do something special when !ViewContext.FormContext.CanRenderAtEndOfForm.

@Eilon Eilon modified the milestones: 2.0.0-preview1, 2.0.0-preview2 Apr 20, 2017
jbagga added a commit that referenced this issue May 5, 2017
@jbagga jbagga closed this as completed May 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants