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

Moving the generated hidden tags for checkbox to the end of the form #3311

Merged
merged 1 commit into from
Oct 14, 2015

Conversation

ajaybhargavb
Copy link
Contributor


namespace Microsoft.AspNet.Mvc.Razor.TagHelpers
{
[EditorBrowsable(EditorBrowsableState.Never)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • docs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? For the EditorBrowsable bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that it doesn't show up in intellisense.

@dougbu
Copy link
Member

dougbu commented Oct 13, 2015

@@ -42,6 +42,10 @@ public class MvcRazorHost : RazorEngineHost, IMvcRazorHost
{
LookupText = "Microsoft.AspNet.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNet.Mvc.Razor"
},
new AddTagHelperChunk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke to @Eilon - instead of doing this, move it to Microsoft.AspNet.Mvc.TagHelpers. Users will import it via _ViewImports.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pranavkm @Eilon if we do this, @Html.CheckBox() and @Html.CheckBoxFor() will not work correctly inside a regular <form> element.

@pranavkm
Copy link
Contributor

@ajaybhargavb
Copy link
Contributor Author

Updated.

/// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)]
[HtmlTargetElement("form")]
public class HiddenFormTagHelper : TagHelper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be more general w/ these descriptions and names. Check boxes are one use of the infrastructure this helper provides. Perhaps ... to generate deferred content before the &lt;/form&gt; end tag. and RenderBeforeFormEndTagTagHelper?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our discussion yesterday, this shouldn't say anything at all about anything being deferred. It's really entirely just about rendering stuff before the end of the form.

@dougbu
Copy link
Member

dougbu commented Oct 14, 2015

/// <summary>
/// <see cref="ITagHelper"/> implementation targeting all form elements to generate hidden tag for checkboxes.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EditorBrowsableState.Advanced wont do anything. Is there a follow up bug to make Razor treat Advanced like Never?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just be Never.

@Eilon
Copy link
Member

Eilon commented Oct 14, 2015

Looking really nice!

@@ -94,5 +94,5 @@
<option>1002</option>
</select>
</div> <input type="submit" />
</form></body>
<input name="[0].Remote" type="hidden" value="false" /><input name="[1].Remote" type="hidden" value="false" /><input name="[2].Remote" type="hidden" value="false" /></form></body>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important here but at some point we should probably change the rendering to output void input tags.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NTaylorMullen we test both with and without the slash. Are you suggesting we test only without?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nooo, testing isn't what I'm referring to. I'm saying that we should always generate without.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought we decided long ago not to mess w/ how the user wrote an element in the .cshtml file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't what the user wrote though. These are generated to pass data to the server on post.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you're talking specifically about revisiting our decision to write these additional <input/> (or <input>) elements identically to the check boxes. Right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'm curious what has changed since we made that decision but let's take this offline. Unrelated to @ajaybhargavb's work here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be generating <self-closing /> tags to be XHTML compliant, which some people care about. It's never wrong, is it?

@ajaybhargavb ajaybhargavb force-pushed the checkbox-order branch 2 times, most recently from b7c9d9e to 6f5bdfe Compare October 14, 2015 18:51
@dougbu
Copy link
Member

dougbu commented Oct 14, 2015

@ajaybhargavb is this updated and ready for another review round?

@ajaybhargavb
Copy link
Contributor Author

@dougbu yes. Forgot to mention.

@ajaybhargavb
Copy link
Contributor Author

Updated.

var formContext = ViewContext.FormContext;
if (formContext.HasEndOfFormContent)
{
foreach (var hiddenTag in formContext.EndOfFormContent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hiddenTag -> content

@dougbu
Copy link
Member

dougbu commented Oct 14, 2015

:shipit: with just a couple of teensy changes


[Theory]
[MemberData(nameof(RenderAtEndOfFormTagHelperData))]
public async Task Process_AddsHiddenInputTag_FromFormData(List<TagBuilder> tagBuilderList, string expectedOutput)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update test name to not say FormData

@Eilon
Copy link
Member

Eilon commented Oct 14, 2015

Looking great, :shipit: after tiny comments.

…form

- #2994
- Affects both HtmlHelper and TagHelper scenarios
- Checkboxes not enclosed in a form will generate inline hidden tags
- Added necessary properties to FormContext
- Added some functional and unit tests
@ajaybhargavb ajaybhargavb merged commit d40e661 into dev Oct 14, 2015
@ajaybhargavb ajaybhargavb deleted the checkbox-order branch October 14, 2015 22:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants