HTMLHelper Option to put wrap <input> with <label> instead of closing <label> first


When using <label>, HTMLHelper wants to draw them as follows:

<label for="foo">Foo Goes Here</label>
<input type="text" name="foo">

This is what we want too – nearly all of the time. We have one client using the Pure CSS library and for checkboxes and radio buttons, it wants this:

<label for="foo">Foo?
<input type="checkbox" name="foo" value=1>

As best I can tell, there is nothing invalid about doing it this way, even if it's inconsistent (even with the rest of the Pure CSS library) but then radio buttons and checkboxes are always divas.

We already hacked HTMLHelper to add an option to render the label tag in the required manner. We just need to write some tests for it and make sure it works with label wrapppers. I'm also not in love with the name of the argument we used – we were in a bit of a hurry and just made a boolean labelAfter (default false) argument that, if true, closes the label tag after the input rather than before it. It might be more clear to call it inputInsideLabel and have it default to true, but whatever you think is most in keeping with HTMLHelper now.


Luis Majano
November 30, 2017, 8:13 PM

I think this is a good ticket!! Go ahead and submit the pull and we can go over the code review.



Samuel W. Knowlton


Samuel W. Knowlton




Fix versions

Affects versions