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

Populate the label 'for' with the control id #41

Merged
merged 1 commit into from Jul 24, 2015

Conversation

liamdavies
Copy link
Contributor

The label 'for' attribute should reflect the id of the labelled control, not the name.

The population of the 'for' attribute for the label has been tied to the name field of the attached control. This has worked fine when using a simple property in the control expression, since the id and name are always equivalent, such as:

Html.Bootstrap().InputFor(x => x.PropA)
generates
    <label for="PropA" class="control-label">Property A</label>
    <input type="text" name="PropA" id="PropA" class="form-control">

However if a complex expression is used, then the input 'id' must be sanitized, and the name must remain unsanitized so that the complex model can be model bound when posted. With the existing code the name is also sanitized, which breaks the default MVC model binding for complex properties.

Html.Bootstrap().InputFor(x => x.Child.ChildPropA)
should generate
    <label for="Child_ChildPropA" class="control-label">Child Property A</label>
    <input type="text" name="Child.ChildPropA" id="Child_ChildPropA" class="form-control">

This change implements this correct behaviour for complex properties.

The label 'for' attribute should reflect the id of the labelled control,
not the name.
@daveaglick
Copy link
Owner

This looks excellent, thanks a lot. I'll pull it in tomorrow and prepare a new release for NuGet.

@daveaglick daveaglick merged commit cb0ec26 into daveaglick:develop Jul 24, 2015
@daveaglick
Copy link
Owner

Thanks again - releasing to NuGet in an hour or two (once I get everything updated to Bootstrap 3.3.5)

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.

None yet

2 participants